home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / c-typeck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-18  |  109.1 KB  |  3,732 lines

  1. /* Build expressions with type checking for C compiler.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file is part of the C front end.
  22.    It contains routines to build C expressions given their operands,
  23.    including computing the types of the result, C-specific error checks,
  24.    and some optimization.
  25.  
  26.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  27.    and to process initializations in declarations (since they work
  28.    like a strange sort of assignment).  */
  29.  
  30. #include "config.h"
  31. #include <stdio.h>
  32. #include "tree.h"
  33. #include "c-tree.h"
  34. #include "flags.h"
  35.  
  36.  
  37.  
  38. int mark_addressable ();
  39. static tree convert_for_assignment ();
  40. static int compparms ();
  41. int comp_target_types ();
  42. static tree shorten_compare ();
  43. static void binary_op_error ();
  44. static tree pointer_int_sum ();
  45. static tree pointer_diff ();
  46. static tree convert_sequence ();
  47. static tree unary_complex_lvalue ();
  48. static tree process_init_constructor ();
  49. tree digest_init ();
  50. tree truthvalue_conversion ();
  51. static tree invert_truthvalue ();
  52. void incomplete_type_error ();
  53. void readonly_warning ();
  54.  
  55. /* Return the _TYPE node describing the data type
  56.    of the data which NODE represents as a C expression.
  57.    Arrays and functions are converted to pointers
  58.    just as they are when they appear as C expressions.  */
  59.  
  60. tree
  61. datatype (node)
  62.      tree node;
  63. {
  64.   register tree type = TREE_TYPE (node);
  65.   if (TREE_CODE (type) == ARRAY_TYPE)
  66.     return TYPE_POINTER_TO (TREE_TYPE (type));
  67.   if (TREE_CODE (type) == FUNCTION_TYPE)
  68.     return build_pointer_type (type);
  69.   return type;
  70. }
  71.  
  72. /* Do `exp = require_complete_type (exp);' to make sure exp
  73.    does not have an incomplete type.  (That includes void types.)  */
  74.  
  75. tree
  76. require_complete_type (value)
  77.      tree value;
  78. {
  79.   tree type = TREE_TYPE (value);
  80.  
  81.   /* First, detect a valid value with a complete type.  */
  82.   if (TYPE_SIZE (type) != 0
  83.       && type != void_type_node)
  84.     return value;
  85.  
  86.   incomplete_type_error (value, type);
  87.   return error_mark_node;
  88. }
  89.  
  90. /* Print an error message for invalid use of an incomplete type.
  91.    VALUE is the expression that was used (or 0 if that isn't known)
  92.    and TYPE is the type that was invalid.  */
  93.  
  94. void
  95. incomplete_type_error (value, type)
  96.      tree value;
  97.      tree type;
  98. {
  99.   char *errmsg;
  100.  
  101.   /* Avoid duplicate error message.  */
  102.   if (TREE_CODE (type) == ERROR_MARK)
  103.     return;
  104.  
  105.   if (value != 0 && (TREE_CODE (value) == VAR_DECL
  106.              || TREE_CODE (value) == PARM_DECL))
  107.     error ("`%s' has an incomplete type",
  108.        IDENTIFIER_POINTER (DECL_NAME (value)));
  109.   else
  110.     {
  111.     retry:
  112.       /* We must print an error message.  Be clever about what it says.  */
  113.  
  114.       switch (TREE_CODE (type))
  115.     {
  116.     case RECORD_TYPE:
  117.       errmsg = "invalid use of undefined type `struct %s'";
  118.       break;
  119.  
  120.     case UNION_TYPE:
  121.       errmsg = "invalid use of undefined type `union %s'";
  122.       break;
  123.  
  124.     case ENUMERAL_TYPE:
  125.       errmsg = "invalid use of undefined type `enum %s'";
  126.       break;
  127.  
  128.     case VOID_TYPE:
  129.       error ("invalid use of void expression");
  130.       return;
  131.  
  132.     case ARRAY_TYPE:
  133.       if (TYPE_DOMAIN (type))
  134.         {
  135.           type = TREE_TYPE (type);
  136.           goto retry;
  137.         }
  138.       error ("invalid use of array with unspecified bounds");
  139.       return;
  140.  
  141.     default:
  142.       abort ();
  143.     }
  144.  
  145.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  146.     error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  147.       else
  148.     /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  149.     error ("invalid use of incomplete typedef `%s'",
  150.            IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  151.     }
  152. }
  153.  
  154. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  155.    as well as those of TYPE.  */
  156.  
  157. static tree
  158. qualify_type (type, like)
  159.      tree type, like;
  160. {
  161.   int constflag = TREE_READONLY (type) || TREE_READONLY (like);
  162.   int volflag = TREE_VOLATILE (type) || TREE_VOLATILE (like);
  163.   return build_type_variant (type, constflag, volflag);
  164. }
  165.  
  166. /* Return the common type of two types.
  167.    We assume that comptypes has already been done and returned 1;
  168.    if that isn't so, this may crash.
  169.  
  170.    This is the type for the result of most arithmetic operations
  171.    if the operands have the given two types.
  172.  
  173.    We do not deal with enumeral types here because they have already been
  174.    converted to integer types.  */
  175.  
  176. tree
  177. commontype (t1, t2)
  178.      tree t1, t2;
  179. {
  180.   register enum tree_code form1;
  181.   register enum tree_code form2;
  182.  
  183.   /* Save time if the two types are the same.  */
  184.  
  185.   if (t1 == t2) return t1;
  186.  
  187.   /* If one type is nonsense, use the other.  */
  188.   if (t1 == error_mark_node)
  189.     return t2;
  190.   if (t2 == error_mark_node)
  191.     return t1;
  192.  
  193.   /* Treat an enum type as the unsigned integer type of the same width.  */
  194.  
  195.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  196.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  197.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  198.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  199.  
  200.   form1 = TREE_CODE (t1);
  201.   form2 = TREE_CODE (t2);
  202.  
  203.   switch (form1)
  204.     {
  205.     case INTEGER_TYPE:
  206.     case REAL_TYPE:
  207.       /* If only one is real, use it as the result.  */
  208.  
  209.       if (form1 == REAL_TYPE && form2 != REAL_TYPE)
  210.     return t1;
  211.  
  212.       if (form2 == REAL_TYPE && form1 != REAL_TYPE)
  213.     return t2;
  214.  
  215.       /* Both real or both integers; use the one with greater precision.  */
  216.  
  217.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  218.     return t1;
  219.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  220.     return t2;
  221.  
  222.       /* Same precision.  Prefer longs to ints even when same size.  */
  223.  
  224.       if (t1 == long_unsigned_type_node
  225.       || t2 == long_unsigned_type_node)
  226.     return long_unsigned_type_node;
  227.  
  228.       if (t1 == long_integer_type_node
  229.       || t2 == long_integer_type_node)
  230.     {
  231.       /* But preserve unsignedness from the other type,
  232.          since long cannot hold all the values of an unsigned int.  */
  233.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  234.         return long_unsigned_type_node;
  235.       return long_integer_type_node;
  236.     }
  237.  
  238.       /* Otherwise prefer the unsigned one.  */
  239.  
  240.       if (TREE_UNSIGNED (t1))
  241.     return t1;
  242.       else return t2;
  243.  
  244.     case POINTER_TYPE:
  245. #if 0
  246.       /* For two pointers, do this recursively on the target type,
  247.      and combine the qualifiers of the two types' targets.  */
  248.       {
  249.     tree target = commontype (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  250.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  251.     int constp
  252.       = TREE_READ_ONLY (TREE_TYPE (t1)) || TREE_READ_ONLY (TREE_TYPE (t2));
  253.     int volatilep
  254.       = TREE_VOLATILE (TREE_TYPE (t1)) || TREE_VOLATILE (TREE_TYPE (t2));
  255.     return build_pointer_type (build_type_variant (target, constp, volatilep));
  256.       }
  257. #endif
  258.       return build_pointer_type (commontype (TREE_TYPE (t1), TREE_TYPE (t2)));
  259.  
  260.     case ARRAY_TYPE:
  261.       {
  262.     tree elt = commontype (TREE_TYPE (t1), TREE_TYPE (t2));
  263.     /* Save space: see if the result is identical to one of the args.  */
  264.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  265.       return t1;
  266.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  267.       return t2;
  268.     /* Merge the element types, and have a size if either arg has one.  */
  269.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  270.       }
  271.  
  272.     case FUNCTION_TYPE:
  273.       /* Function types: prefer the one that specified arg types.
  274.      If both do, merge the arg types.  Also merge the return types.  */
  275.       {
  276.     tree valtype = commontype (TREE_TYPE (t1), TREE_TYPE (t2));
  277.     tree p1 = TYPE_ARG_TYPES (t1);
  278.     tree p2 = TYPE_ARG_TYPES (t2);
  279.     int len;
  280.     tree newargs, n;
  281.     int i;
  282.  
  283.     /* Save space: see if the result is identical to one of the args.  */
  284.     if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
  285.       return t1;
  286.     if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
  287.       return t2;
  288.  
  289.     /* Simple way if one arg fails to specify argument types.  */
  290.     if (TYPE_ARG_TYPES (t1) == 0)
  291.       return build_function_type (valtype, TYPE_ARG_TYPES (t2));
  292.     if (TYPE_ARG_TYPES (t2) == 0)
  293.       return build_function_type (valtype, TYPE_ARG_TYPES (t1));
  294.  
  295.     /* If both args specify argument types, we must merge the two
  296.        lists, argument by argument.  */
  297.  
  298.     len = list_length (p1);
  299.     newargs = 0;
  300.  
  301.     for (i = 0; i < len; i++)
  302.       newargs = tree_cons (0, 0, newargs);
  303.  
  304.     n = newargs;
  305.  
  306.     for (; p1;
  307.          p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
  308.       TREE_VALUE (n) = commontype (TREE_VALUE (p1), TREE_VALUE (p2));
  309.  
  310.     return build_function_type (valtype, newargs);
  311.       }
  312.  
  313.     default:
  314.       return t1;
  315.     }
  316.  
  317. }
  318.  
  319. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  320.    or various other operations.  This is what ANSI C speaks of as
  321.    "being the same".  */
  322.  
  323. int
  324. comptypes (type1, type2)
  325.      tree type1, type2;
  326. {
  327.   register tree t1 = type1;
  328.   register tree t2 = type2;
  329.  
  330.   /* Suppress errors caused by previously reported errors */
  331.  
  332.   if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
  333.     return 1;
  334.  
  335.   /* Treat an enum type as the unsigned integer type of the same width.  */
  336.  
  337.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  338.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  339.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  340.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  341.  
  342.   if (t1 == t2)
  343.     return 1;
  344.  
  345.   /* Different classes of types can't be compatible.  */
  346.  
  347.   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
  348.  
  349.   /* Qualifiers must match.  */
  350.  
  351.   if (TREE_READONLY (t1) != TREE_READONLY (t2))
  352.     return 0;
  353.   if (TREE_THIS_VOLATILE (t1) != TREE_THIS_VOLATILE (t2))
  354.     return 0;
  355.  
  356.   switch (TREE_CODE (t1))
  357.     {
  358.     case POINTER_TYPE:
  359.       return (TREE_TYPE (t1) == TREE_TYPE (t2)
  360.           || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
  361.  
  362.     case FUNCTION_TYPE:
  363.       return ((TREE_TYPE (t1) == TREE_TYPE (t2)
  364.            || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
  365.           && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)));
  366.  
  367.     case ARRAY_TYPE:
  368.       /* Target types must match incl. qualifiers.  */
  369.       if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  370.         || comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
  371.     return 0;
  372.       {
  373.     tree d1 = TYPE_DOMAIN (t1);
  374.     tree d2 = TYPE_DOMAIN (t2);
  375.  
  376.     /* Sizes must match unless one is missing or variable.  */
  377.     if (d1 == 0 || d2 == 0 || d1 == d2
  378.         || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  379.         || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  380.         || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  381.         || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  382.       return 1;
  383.  
  384.     return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  385.          == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  386.         && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  387.             == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  388.         && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  389.             == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  390.         && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  391.             == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  392.       }
  393.     }
  394.   return 0;
  395. }
  396.  
  397. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  398.    ignoring their qualifiers.  */
  399.  
  400. int
  401. comp_target_types (ttl, ttr)
  402.      tree ttl, ttr;
  403. {
  404.   return comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  405.             TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  406. }
  407.  
  408. /* Subroutines of `comptypes'.  */
  409.  
  410. /* Return 1 if two parameter type lists PARMS1 and PARMS2
  411.    are equivalent in the sense that functions with those parameter types
  412.    can have equivalent types.
  413.    If either list is empty, we win.
  414.    Otherwise, the two lists must be equivalent, element by element.  */
  415.  
  416. static int
  417. compparms (parms1, parms2)
  418.      tree parms1, parms2;
  419. {
  420.   register tree t1 = parms1, t2 = parms2;
  421.  
  422.   /* An unspecified parmlist matches any specified parmlist
  423.      whose argument types don't need default promotions.  */
  424.  
  425.   if (t1 == 0)
  426.     return compparms1 (t2);
  427.   if (t2 == 0)
  428.     return compparms1 (t1);
  429.  
  430.   while (1)
  431.     {
  432.       if (t1 == 0 && t2 == 0)
  433.     return 1;
  434.       /* If one parmlist is shorter than the other,
  435.      they fail to match.  */
  436.       if (t1 == 0 || t2 == 0)
  437.     return 0;
  438.       if (! comptypes (TREE_VALUE (t1), TREE_VALUE (t2)))
  439.     return 0;
  440.       t1 = TREE_CHAIN (t1);
  441.       t2 = TREE_CHAIN (t2);
  442.     }
  443. }
  444.  
  445. /* Return 1 if PARMS specifies a fixed number of parameters
  446.    and none of their types is affected by default promotions.  */
  447.  
  448. int
  449. compparms1 (parms)
  450.      tree parms;
  451. {
  452.   register tree t;
  453.   for (t = parms; t; t = TREE_CHAIN (t))
  454.     {
  455.       register tree type = TREE_VALUE (t);
  456.  
  457.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  458.     return 0;
  459.  
  460.       if (type == float_type_node)
  461.     return 0;
  462.  
  463.       if (TREE_CODE (type) == INTEGER_TYPE
  464.       && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  465.     return 0;
  466.     }
  467.   return 1;
  468. }
  469.  
  470. /* Return an unsigned type the same as TYPE in other respects.  */
  471.  
  472. tree
  473. unsigned_type (type)
  474.      tree type;
  475. {
  476.   if (type == signed_char_type_node || type == char_type_node)
  477.     return unsigned_char_type_node;
  478.   if (type == integer_type_node)
  479.     return unsigned_type_node;
  480.   if (type == short_integer_type_node)
  481.     return short_unsigned_type_node;
  482.   if (type == long_integer_type_node)
  483.     return long_unsigned_type_node;
  484.   if (type == long_long_integer_type_node)
  485.     return long_long_unsigned_type_node;
  486.   return type;
  487. }
  488.  
  489. /* Return a signed type the same as TYPE in other respects.  */
  490.  
  491. tree
  492. signed_type (type)
  493.      tree type;
  494. {
  495.   if (type == unsigned_char_type_node || type == char_type_node)
  496.     return signed_char_type_node;
  497.   if (type == unsigned_type_node)
  498.     return integer_type_node;
  499.   if (type == short_unsigned_type_node)
  500.     return short_integer_type_node;
  501.   if (type == long_unsigned_type_node)
  502.     return long_integer_type_node;
  503.   if (type == long_long_unsigned_type_node)
  504.     return long_long_integer_type_node;
  505.   return type;
  506. }
  507.  
  508. /* Return a type the same as TYPE except unsigned or
  509.    signed according to UNSIGNEDP.  */
  510.  
  511. tree
  512. signed_or_unsigned_type (unsignedp, type)
  513.      int unsignedp;
  514.      tree type;
  515. {
  516.   if (TREE_CODE (type) != INTEGER_TYPE)
  517.     return type;
  518.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  519.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  520.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  521.     return unsignedp ? unsigned_type_node : integer_type_node;
  522.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  523.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  524.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  525.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  526.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  527.     return (unsignedp ? long_long_unsigned_type_node
  528.         : long_long_integer_type_node);
  529.   return type;
  530. }
  531.  
  532. /* Return an integer type with BITS bits of precision,
  533.    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
  534.  
  535. tree
  536. type_for_size (bits, unsignedp)
  537.      int bits;
  538.      int unsignedp;
  539. {
  540.   if (bits <= TYPE_PRECISION (signed_char_type_node))
  541.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  542.  
  543.   if (bits <= TYPE_PRECISION (short_integer_type_node))
  544.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  545.  
  546.   if (bits <= TYPE_PRECISION (integer_type_node))
  547.     return unsignedp ? unsigned_type_node : integer_type_node;
  548.  
  549.   if (bits <= TYPE_PRECISION (long_integer_type_node))
  550.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  551.  
  552.   if (bits <= TYPE_PRECISION (long_long_integer_type_node))
  553.     return (unsignedp ? long_long_unsigned_type_node
  554.         : long_long_integer_type_node);
  555.  
  556.   return 0;
  557. }
  558.  
  559. tree
  560. get_floating_type (mode)
  561.      enum machine_mode mode;
  562. {
  563.   if (mode == TYPE_MODE (float_type_node))
  564.     return float_type_node;
  565.   if (mode == TYPE_MODE (double_type_node))
  566.     return double_type_node;
  567.   if (mode == TYPE_MODE (long_double_type_node))
  568.     return long_double_type_node;
  569.   abort ();
  570. }
  571.  
  572. tree
  573. c_sizeof (type)
  574.      tree type;
  575. {
  576.   enum tree_code code = TREE_CODE (type);
  577.  
  578.   if (code == FUNCTION_TYPE)
  579.     {
  580.       if (pedantic || warn_pointer_arith)
  581.     warning ("sizeof applied to a function type");
  582.       return build_int (1);
  583.     }
  584.   if (code == VOID_TYPE)
  585.     {
  586.       if (pedantic || warn_pointer_arith)
  587.     warning ("sizeof applied to a void type");
  588.       return build_int (1);
  589.     }
  590.  
  591.   /* Convert in case a char is more than one unit.  */
  592.   return convert_units (size_in_bytes (type), BITS_PER_UNIT,
  593.             TYPE_PRECISION (char_type_node));
  594. }
  595.  
  596. tree
  597. c_sizeof_nowarn (type)
  598.      tree type;
  599. {
  600.   enum tree_code code = TREE_CODE (type);
  601.  
  602.   if (code == FUNCTION_TYPE
  603.       || code == VOID_TYPE)
  604.     return build_int (1);
  605.  
  606.   /* Convert in case a char is more than one unit.  */
  607.   return convert_units (size_in_bytes (type), BITS_PER_UNIT,
  608.             TYPE_PRECISION (char_type_node));
  609. }
  610.  
  611. /* Implement the __alignof keyword: Return the minimum required
  612.    alignment of TYPE, measured in bytes.  */
  613.  
  614. tree
  615. c_alignof (type)
  616.      tree type;
  617. {
  618.   enum tree_code code = TREE_CODE (type);
  619.  
  620.   if (code == FUNCTION_TYPE)
  621.     return build_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  622.  
  623.   if (code == VOID_TYPE)
  624.     return build_int (1);
  625.  
  626.   return build_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  627. }
  628.  
  629. /* Return either DECL or its known constant value (if it has one).  */
  630.  
  631. static tree
  632. decl_constant_value (decl)
  633.      tree decl;
  634. {
  635.   if (! TREE_PUBLIC (decl)
  636.       /* Don't change a variable array bound or initial value to a constant
  637.      in a place where a variable is invalid.  */
  638.       && current_function_decl != 0
  639.       && ! pedantic
  640.       && ! TREE_THIS_VOLATILE (decl)
  641.       && DECL_INITIAL (decl) != 0
  642.       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
  643.       /* This is invalid if initial value is not constant.
  644.      If it has either a function call, a memory reference,
  645.      or a variable, then re-evaluating it could give different results.  */
  646.       && TREE_LITERAL (DECL_INITIAL (decl))
  647.       /* Check for cases where this is sub-optimal, even though valid.  */
  648.       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  649.       && DECL_MODE (decl) != BLKmode)
  650.     return DECL_INITIAL (decl);
  651.   return decl;
  652. }
  653.  
  654. /* Perform default promotions for C data used in expressions.
  655.    Arrays and functions are converted to pointers;
  656.    enumeral types or short or char, to int.
  657.    In addition, manifest constants symbols are replaced by their values.  */
  658.  
  659. tree
  660. default_conversion (exp)
  661.      tree exp;
  662. {
  663.   register tree dt = TREE_TYPE (exp);
  664.   register enum tree_code form = TREE_CODE (dt);
  665.  
  666.   if (TREE_CODE (exp) == CONST_DECL)
  667.     exp = DECL_INITIAL (exp);
  668.   /* Replace a nonvolatile const static variable with its value.  */
  669.   else if (optimize
  670.        && TREE_CODE (exp) == VAR_DECL
  671.        && TREE_READONLY (exp))
  672.     exp = decl_constant_value (exp);
  673.  
  674.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  675.      Strip such NOP_EXPRs, since EXP is being used in non-lvalue context.  */
  676.   if (TREE_CODE (exp) == NOP_EXPR
  677.       && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
  678.     exp = TREE_OPERAND (exp, 0);
  679.  
  680.   if (form == ENUMERAL_TYPE
  681.       || (form == INTEGER_TYPE
  682.       && (TYPE_PRECISION (dt)
  683.           < TYPE_PRECISION (integer_type_node))))
  684.     {
  685.       /* Traditionally, unsignedness is preserved in default promotions.  */
  686.       if (flag_traditional && TREE_UNSIGNED (dt))
  687.     return convert (unsigned_type_node, exp);
  688.       return convert (integer_type_node, exp);
  689.     }
  690.   if (flag_traditional && dt == float_type_node)
  691.     return convert (double_type_node, exp);
  692.   if (form == VOID_TYPE)
  693.     {
  694.       error ("void value not ignored as it ought to be");
  695.       return error_mark_node;
  696.     }
  697.   if (form == FUNCTION_TYPE)
  698.     {
  699.       return build_unary_op (ADDR_EXPR, exp, 0);
  700.     }
  701.   if (form == ARRAY_TYPE)
  702.     {
  703.       register tree adr;
  704.       tree restype = TREE_TYPE (dt);
  705.       tree ptrtype;
  706.  
  707.       if (TREE_CODE (exp) == INDIRECT_REF)
  708.     return convert (TYPE_POINTER_TO (restype),
  709.             TREE_OPERAND (exp, 0));
  710.  
  711.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  712.     {
  713.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  714.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  715.             TREE_OPERAND (exp, 0), op1);
  716.     }
  717.  
  718.       if (!lvalue_p (exp)
  719.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  720.     {
  721.       error ("invalid use of non-lvalue array");
  722.       return error_mark_node;
  723.     }
  724.  
  725.       if (TREE_READONLY (exp) || TREE_THIS_VOLATILE (exp))
  726.     restype = build_type_variant (restype, TREE_READONLY (exp),
  727.                       TREE_THIS_VOLATILE (exp));
  728.  
  729.       ptrtype = build_pointer_type (restype);
  730.  
  731.       if (TREE_CODE (exp) == VAR_DECL)
  732.     {
  733.       /* ??? This is not really quite correct
  734.          in that the type of the operand of ADDR_EXPR
  735.          is not the target type of the type of the ADDR_EXPR itself.
  736.          Question is, can this lossage be avoided?  */
  737.       adr = build (ADDR_EXPR, ptrtype, exp);
  738.       if (mark_addressable (exp) == 0)
  739.         return error_mark_node;
  740.       TREE_LITERAL (adr) = staticp (exp);
  741.       TREE_VOLATILE (adr) = 0;   /* Default would be, same as EXP.  */
  742.       return adr;
  743.     }
  744.       /* This way is better for a COMPONENT_REF since it can
  745.      simplify the offset for a component.  */
  746.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  747.       return convert (ptrtype, adr);
  748.     }
  749.   return exp;
  750. }
  751.  
  752. /* Make an expression to refer to the COMPONENT field of
  753.    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
  754.  
  755. tree
  756. build_component_ref (datum, component)
  757.      tree datum, component;
  758. {
  759.   register tree basename = datum;
  760.   register tree basetype = TREE_TYPE (basename);
  761.   register enum tree_code form = TREE_CODE (basetype);
  762.   register tree field = NULL;
  763.   register tree ref;
  764.  
  765.   /* First, see if there is a field or component with name COMPONENT. */
  766.  
  767.   if (form == RECORD_TYPE || form == UNION_TYPE)
  768.     {
  769.       if (TYPE_SIZE (basetype) == 0)
  770.     {
  771.       incomplete_type_error (0, basetype);
  772.       return error_mark_node;
  773.     }
  774.  
  775.       /* Look up component name in the structure type definition.  */
  776.  
  777.       for (field = TYPE_FIELDS (basetype); field; field = TREE_CHAIN (field))
  778.     {
  779.       if (DECL_NAME (field) == component)
  780.         break;
  781.     }
  782.  
  783.       if (!field)
  784.     {
  785.       error (form == RECORD_TYPE
  786.          ? "structure has no member named `%s'"
  787.          : "union has no member named `%s'",
  788.          IDENTIFIER_POINTER (component));
  789.       return error_mark_node;
  790.     }
  791.       if (TREE_TYPE (field) == error_mark_node)
  792.     return error_mark_node;
  793.  
  794.       ref = build (COMPONENT_REF, TREE_TYPE (field), basename, field);
  795.  
  796.       if (TREE_READONLY (basename) || TREE_READONLY (field))
  797.     TREE_READONLY (ref) = 1;
  798.       if (TREE_THIS_VOLATILE (basename) || TREE_VOLATILE (field))
  799.     TREE_THIS_VOLATILE (ref) = 1;
  800.  
  801.       return ref;
  802.     }
  803.   else if (form != ERROR_MARK)
  804.     error ("request for member `%s' in something not a structure or union",
  805.         IDENTIFIER_POINTER (component));
  806.  
  807.   return error_mark_node;
  808. }
  809.  
  810. /* Given an expression PTR for a pointer, return an expression
  811.    for the value pointed to.
  812.    ERRORSTRING is the name of the operator to appear in error messages.  */
  813.  
  814. tree
  815. build_indirect_ref (ptr, errorstring)
  816.      tree ptr;
  817.      char *errorstring;
  818. {
  819.   register tree pointer = default_conversion (ptr);
  820.   register tree dt = TREE_TYPE (pointer);
  821.  
  822.   if (TREE_CODE (dt) == POINTER_TYPE)
  823.     if (TREE_CODE (pointer) == ADDR_EXPR
  824.     && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  825.         == TREE_TYPE (dt)))
  826.       return TREE_OPERAND (pointer, 0);
  827.     else
  828.       {
  829.     tree t = TREE_TYPE (dt);
  830.     register tree ref = build (INDIRECT_REF,
  831.                    TYPE_MAIN_VARIANT (t), pointer);
  832.  
  833.     TREE_READONLY (ref) = TREE_READONLY (t);
  834.     TREE_VOLATILE (ref) = TREE_VOLATILE (t) || TREE_VOLATILE (pointer);
  835.     TREE_THIS_VOLATILE (ref) = TREE_VOLATILE (t);
  836.     return ref;
  837.       }
  838.   else if (TREE_CODE (pointer) != ERROR_MARK)
  839.     error ("invalid type argument of `%s'", errorstring);
  840.   return error_mark_node;
  841. }
  842.  
  843. /* This handles expressions of the form "a[i]", which denotes
  844.    an array reference.
  845.  
  846.    This is logically equivalent in C to *(a+i), but we may do it differently.
  847.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  848.    This avoids forcing the array out of registers, and can work on
  849.    arrays that are not lvalues (for example, members of structures returned
  850.    by functions).  */
  851.  
  852. tree
  853. build_array_ref (array, index)
  854.      tree array, index;
  855. {
  856.   if (index == 0)
  857.     {
  858.       error ("subscript missing in array reference");
  859.       return error_mark_node;
  860.     }
  861.  
  862.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  863.       && TREE_CODE (array) != INDIRECT_REF)
  864.     {
  865.       tree rval;
  866.  
  867.       index = default_conversion (index);
  868.       if (index != error_mark_node
  869.       && TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
  870.     {
  871.       error ("array subscript is not an integer");
  872.       return error_mark_node;
  873.     }
  874.  
  875.       /* An array that is indexed by a non-constant
  876.      cannot be stored in a register; we must be able to do
  877.      address arithmetic on its address.
  878.      Likewise an array of elements of variable size.  */
  879.       if (TREE_CODE (index) != INTEGER_CST
  880.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  881.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  882.     {
  883.       if (mark_addressable (array) == 0)
  884.         return error_mark_node;
  885.     }
  886.  
  887.       if (pedantic && !lvalue_p (array))
  888.     warning ("ANSI C forbids subscripting non-lvalue array");
  889.  
  890.       if (pedantic)
  891.     {
  892.       tree foo = array;
  893.       while (TREE_CODE (foo) == COMPONENT_REF)
  894.         foo = TREE_OPERAND (foo, 0);
  895.       if (TREE_CODE (foo) == VAR_DECL && TREE_REGDECL (foo))
  896.         warning ("ANSI C forbids subscripting non-lvalue array");
  897.     }
  898.  
  899.       rval = build (ARRAY_REF, TREE_TYPE (TREE_TYPE (array)), array, index);
  900.       /* Array ref is const/volatile if the array elements are.  */
  901.       TREE_READONLY (rval) |= TREE_READONLY (TREE_TYPE (TREE_TYPE (array)));
  902.       TREE_VOLATILE (rval) |= TREE_VOLATILE (TREE_TYPE (TREE_TYPE (array)));
  903.       TREE_THIS_VOLATILE (rval) |= TREE_VOLATILE (TREE_TYPE (TREE_TYPE (array)));
  904.       return require_complete_type (fold (rval));
  905.     }
  906.  
  907.   {
  908.     tree ar = default_conversion (array);
  909.     tree ind = default_conversion (index);
  910.  
  911.     if ((TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE
  912.      && TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  913.     || (TREE_CODE (TREE_TYPE (ind)) == POINTER_TYPE
  914.         && TREE_CODE (TREE_TYPE (ar)) != INTEGER_TYPE))
  915.       {
  916.     error ("array subscript is not an integer");
  917.     return error_mark_node;
  918.       }
  919.  
  920.     return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR),
  921.                    "array indexing");
  922.   }
  923. }
  924.  
  925. /* Build a function call to function FUNCTION with parameters PARAMS.
  926.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  927.    TREE_VALUE of each node is a parameter-expression.
  928.    FUNCTION's data type may be a function type or a pointer-to-function.  */
  929.  
  930. tree
  931. build_function_call (function, params)
  932.      tree function, params;
  933. {
  934.   register tree fntype;
  935.   register tree value_type;
  936.   register tree coerced_params;
  937.   tree name = NULL_TREE;
  938.   tree actualparameterlist ();
  939.  
  940.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  941.      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
  942.   if (TREE_CODE (function) == NOP_EXPR
  943.       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
  944.     function = TREE_OPERAND (function, 0);
  945.  
  946.   /* Convert anything with function type to a pointer-to-function.  */
  947.   if (TREE_CODE (function) == FUNCTION_DECL)
  948.     {
  949.       name = DECL_NAME (function);
  950.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  951.      (because calling an inline function does not mean the function
  952.      needs to be separately compiled).  */
  953.       function = build (ADDR_EXPR, build_pointer_type (TREE_TYPE (function)),
  954.             function);
  955.     }
  956.   else
  957.     function = default_conversion (function);
  958.  
  959.   fntype = TREE_TYPE (function);
  960.  
  961.   if (TREE_CODE (fntype) == ERROR_MARK)
  962.     return error_mark_node;
  963.  
  964.   if (!(TREE_CODE (fntype) == POINTER_TYPE
  965.     && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
  966.     {
  967.       error ("called object is not a function");
  968.       return error_mark_node;
  969.     }
  970.  
  971.   /* fntype now gets the type of function pointed to.  */
  972.   fntype = TREE_TYPE (fntype);
  973.  
  974.   /* Convert the parameters to the types declared in the
  975.      function prototype, or apply default promotions.  */
  976.  
  977.   coerced_params = actualparameterlist (TYPE_ARG_TYPES (fntype), params, name);
  978.  
  979.   /* Recognize certain built-in functions so we can make tree-codes
  980.      other than CALL_EXPR.  We do this when it enables fold-const.c
  981.      to do something useful.  */
  982.  
  983.   if (TREE_CODE (function) == ADDR_EXPR
  984.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
  985.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  986.       {
  987.       case BUILT_IN_ABS:
  988.       case BUILT_IN_LABS:
  989.       case BUILT_IN_FABS:
  990.     if (coerced_params == 0)
  991.       return integer_zero_node;
  992.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  993.       }
  994.  
  995.   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
  996.   
  997.   {
  998.     register tree result = 
  999.       build (CALL_EXPR, value_type, function, coerced_params, NULL_TREE);
  1000.  
  1001.     TREE_VOLATILE (result) = 1;
  1002.     if (value_type == void_type_node)
  1003.       return result;
  1004.     return require_complete_type (result);
  1005.   }
  1006. }
  1007.  
  1008. /* Convert the actual parameter expressions in the list VALUES
  1009.    to the types in the list TYPELIST.
  1010.    If parmdecls is exhausted, or when an element has NULL as its type,
  1011.    perform the default conversions.
  1012.  
  1013.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  1014.  
  1015.    This is also where warnings about wrong number of args are generated.
  1016.    
  1017.    Return a list of expressions for the parameters as converted.
  1018.  
  1019.    Both VALUES and the returned value are chains of TREE_LIST nodes
  1020.    with the elements of the list in the TREE_VALUE slots of those nodes.  */
  1021.  
  1022. tree
  1023. actualparameterlist (typelist, values, name)
  1024.      tree typelist, values, name;
  1025. {
  1026.   register tree typetail, valtail;
  1027.   register tree result = NULL;
  1028.  
  1029.   for (valtail = values, typetail = typelist;
  1030.        valtail;
  1031.        valtail = TREE_CHAIN (valtail))
  1032.     {
  1033.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  1034.       register tree val = TREE_VALUE (valtail);
  1035.       register tree parm;
  1036.  
  1037.       if (type == void_type_node)
  1038.     {
  1039.       if (name)
  1040.         error ("too many arguments to function `%s'",
  1041.            IDENTIFIER_POINTER (name));
  1042.       else
  1043.         error ("too many arguments to function");
  1044.       break;
  1045.     }
  1046.  
  1047.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  1048.      Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
  1049.       if (TREE_CODE (val) == NOP_EXPR
  1050.       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
  1051.     val = TREE_OPERAND (val, 0);
  1052.  
  1053.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  1054.       || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
  1055.     val = default_conversion (val);
  1056.  
  1057.       val = require_complete_type (val);
  1058.  
  1059.       if (type != 0)
  1060.     {
  1061.       /* Formal parm type is specified by a function prototype.  */
  1062.       tree parmval;
  1063.  
  1064.       if (TYPE_SIZE (type) == 0)
  1065.         {
  1066.           error ("parameter type of called function is incomplete");
  1067.           parmval = val;
  1068.         }
  1069.       else
  1070.         {
  1071. #ifdef PROMOTE_PROTOTYPES
  1072.           /* Rather than truncating and then reextending,
  1073.          convert directly to int, if that's the type we will want.  */
  1074.           if (! flag_traditional
  1075.           && TREE_CODE (type) == INTEGER_TYPE
  1076.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1077.         type = integer_type_node;
  1078. #endif
  1079.           parmval = convert_for_assignment (type, val, "argument passing");
  1080. #ifdef PROMOTE_PROTOTYPES
  1081.           if (TREE_CODE (type) == INTEGER_TYPE
  1082.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1083.         parmval = default_conversion (parmval);
  1084. #endif
  1085.         }
  1086.       parm = build_tree_list (0, parmval);
  1087.     }
  1088.       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  1089.                && (TYPE_PRECISION (TREE_TYPE (val))
  1090.                < TYPE_PRECISION (double_type_node)))
  1091.     /* Convert `float' to `double'.  */
  1092.     parm = build_tree_list (NULL_TREE, convert (double_type_node, val));
  1093.       else
  1094.     /* Convert `short' and `char' to full-size `int'.  */
  1095.     parm = build_tree_list (NULL_TREE, default_conversion (val));
  1096.  
  1097.       result = chainon (result, parm);
  1098.       if (typetail)
  1099.     typetail = TREE_CHAIN (typetail);
  1100.     }
  1101.  
  1102.   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
  1103.     {
  1104.       if (name)
  1105.     error ("too few arguments to function `%s'",
  1106.            IDENTIFIER_POINTER (name));
  1107.       else
  1108.     error ("too few arguments to function");
  1109.     }
  1110.  
  1111.   return result;
  1112. }
  1113.  
  1114. /* Build a binary-operation expression, after performing default
  1115.    conversions on the operands.  CODE is the kind of expression to build.  */
  1116.  
  1117. tree
  1118. build_binary_op (code, arg1, arg2)
  1119.      enum tree_code code;
  1120.      tree arg1, arg2;
  1121. {
  1122.   return build_binary_op_nodefault (code, default_conversion (arg1),
  1123.                     default_conversion (arg2), code);
  1124. }
  1125.  
  1126. /* Build a binary-operation expression without default conversions.
  1127.    CODE is the kind of expression to build.
  1128.    This function differs from `build' in several ways:
  1129.    the data type of the result is computed and recorded in it,
  1130.    warnings are generated if arg data types are invalid,
  1131.    special handling for addition and subtraction of pointers is known,
  1132.    and some optimization is done (operations on narrow ints
  1133.    are done in the narrower type when that gives the same result).
  1134.    Constant folding is also done before the result is returned.
  1135.  
  1136.    ERROR_CODE is the code that determines what to say in error messages.
  1137.    It is usually, but not always, the same as CODE.
  1138.  
  1139.    Note that the operands will never have enumeral types
  1140.    because either they have just had the default conversions performed
  1141.    or they have both just been converted to some other type in which
  1142.    the arithmetic is to be done.  */
  1143.  
  1144. tree
  1145. build_binary_op_nodefault (code, op0, op1, error_code)
  1146.      enum tree_code code;
  1147.      tree op0, op1;
  1148.      enum tree_code error_code;
  1149. {
  1150.   tree dt0 = datatype (op0), dt1 = datatype (op1);
  1151.  
  1152.   /* The expression codes of the data types of the arguments tell us
  1153.      whether the arguments are integers, floating, pointers, etc.  */
  1154.   register enum tree_code code0 = TREE_CODE (dt0);
  1155.   register enum tree_code code1 = TREE_CODE (dt1);
  1156.  
  1157.   /* Expression code to give to the expression when it is built.
  1158.      Normally this is CODE, which is what the caller asked for,
  1159.      but in some special cases we change it.  */
  1160.   register enum tree_code resultcode = code;
  1161.  
  1162.   /* Data type in which the computation is to be performed.
  1163.      In the simplest cases this is the common type of the arguments.  */
  1164.   register tree result_type = NULL;
  1165.  
  1166.   /* Nonzero means operands have already been type-converted
  1167.      in whatever way is necessary.
  1168.      Zero means they need to be converted to RESULT_TYPE.  */
  1169.   int converted = 0;
  1170.  
  1171.   /* Nonzero means after finally constructing the expression
  1172.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  1173.   tree final_type = 0;
  1174.  
  1175.   /* Nonzero if this is an operation like MIN or MAX which can
  1176.      safely be computed in short if both args are promoted shorts.
  1177.      Also implies COMMON.
  1178.      -1 indicates a bitwise operation; this makes a difference
  1179.      in the exact conditions for when it is safe to do the operation
  1180.      in a narrower mode.  */
  1181.   int shorten = 0;
  1182.  
  1183.   /* Nonzero if this is a comparison operation;
  1184.      if both args are promoted shorts, compare the original shorts.
  1185.      Also implies COMMON.  */
  1186.   int short_compare = 0;
  1187.  
  1188.   /* Nonzero if this is a right-shift operation, which can be computed on the
  1189.      original short and then promoted if the operand is a promoted short.  */
  1190.   int short_shift = 0;
  1191.  
  1192.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  1193.   int common = 0;
  1194.  
  1195.   /* If an error was already reported for one of the arguments,
  1196.      avoid reporting another error.  */
  1197.  
  1198.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  1199.     return error_mark_node;
  1200.  
  1201.   switch (code)
  1202.     {
  1203.     case PLUS_EXPR:
  1204.       /* Handle the pointer + int case.  */
  1205.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1206.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  1207.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  1208.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  1209.       else
  1210.     common = 1;
  1211.       break;
  1212.  
  1213.     case MINUS_EXPR:
  1214.       /* Subtraction of two similar pointers.
  1215.      We must subtract them as integers, then divide by object size.  */
  1216.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  1217.       && comp_target_types (dt0, dt1))
  1218.     return pointer_diff (op0, op1);
  1219.       /* Handle pointer minus int.  Just like pointer plus int.  */
  1220.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1221.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  1222.       else
  1223.     common = 1;
  1224.       break;
  1225.  
  1226.     case MULT_EXPR:
  1227.       common = 1;
  1228.       break;
  1229.  
  1230.     case TRUNC_DIV_EXPR:
  1231.     case CEIL_DIV_EXPR:
  1232.     case FLOOR_DIV_EXPR:
  1233.     case ROUND_DIV_EXPR:
  1234.     case EXACT_DIV_EXPR:
  1235.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1236.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1237.     {
  1238.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  1239.         resultcode = RDIV_EXPR;
  1240.       else
  1241.         shorten = 1;
  1242.       common = 1;
  1243.     }
  1244.       break;
  1245.  
  1246.     case BIT_AND_EXPR:
  1247.     case BIT_ANDTC_EXPR:
  1248.     case BIT_IOR_EXPR:
  1249.     case BIT_XOR_EXPR:
  1250.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1251.     shorten = -1;
  1252.       /* If one operand is a constant, and the other is a short type
  1253.      that has been converted to an int,
  1254.      really do the work in the short type and then convert the
  1255.      result to int.  If we are lucky, the constant will be 0 or 1
  1256.      in the short type, making the entire operation go away.  */
  1257.       if (TREE_CODE (op0) == INTEGER_CST
  1258.       && TREE_CODE (op1) == NOP_EXPR
  1259.       && TYPE_PRECISION (dt1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  1260.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  1261.     {
  1262.       final_type = result_type;
  1263.       op1 = TREE_OPERAND (op1, 0);
  1264.       result_type = TREE_TYPE (op1);
  1265.     }
  1266.       if (TREE_CODE (op1) == INTEGER_CST
  1267.       && TREE_CODE (op0) == NOP_EXPR
  1268.       && TYPE_PRECISION (dt0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  1269.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  1270.     {
  1271.       final_type = result_type;
  1272.       op0 = TREE_OPERAND (op0, 0);
  1273.       result_type = TREE_TYPE (op0);
  1274.     }
  1275.       break;
  1276.  
  1277.     case TRUNC_MOD_EXPR:
  1278.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1279.     shorten = 1;
  1280.       break;
  1281.  
  1282.     case TRUTH_ANDIF_EXPR:
  1283.     case TRUTH_ORIF_EXPR:
  1284.     case TRUTH_AND_EXPR:
  1285.     case TRUTH_OR_EXPR:
  1286.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE)
  1287.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE))
  1288.     {
  1289.       /* Result of these operations is always an int,
  1290.          but that does not mean the operands should be
  1291.          converted to ints!  */
  1292.       result_type = integer_type_node;
  1293.       op0 = truthvalue_conversion (op0);
  1294.       op1 = truthvalue_conversion (op1);
  1295.       converted = 1;
  1296.     }
  1297.       break;
  1298.  
  1299.       /* Shift operations: result has same type as first operand;
  1300.      always convert second operand to int.
  1301.      Also set SHORT_SHIFT if shifting rightward.  */
  1302.  
  1303.     case RSHIFT_EXPR:
  1304.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1305.     {
  1306.       result_type = dt0;
  1307.       if (TREE_CODE (op1) == INTEGER_CST
  1308.           && TREE_INT_CST_LOW (op1) > 0)
  1309.         short_shift = 1;
  1310.       /* Convert the shift-count to an integer, regardless of
  1311.          size of value being shifted.  */
  1312.       if (TREE_TYPE (op1) != integer_type_node)
  1313.         op1 = convert (integer_type_node, op1);
  1314.     }
  1315.       break;
  1316.  
  1317.     case LSHIFT_EXPR:
  1318.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1319.     {
  1320.       result_type = dt0;
  1321.       if (TREE_CODE (op1) == INTEGER_CST
  1322.           && TREE_INT_CST_LOW (op1) < 0)
  1323.         short_shift = 1;
  1324.       /* Convert the shift-count to an integer, regardless of
  1325.          size of value being shifted.  */
  1326.       if (TREE_TYPE (op1) != integer_type_node)
  1327.         op1 = convert (integer_type_node, op1);
  1328.     }
  1329.       break;
  1330.  
  1331.     case RROTATE_EXPR:
  1332.     case LROTATE_EXPR:
  1333.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1334.     {
  1335.       result_type = dt0;
  1336.       /* Convert the shift-count to an integer, regardless of
  1337.          size of value being shifted.  */
  1338.       if (TREE_TYPE (op1) != integer_type_node)
  1339.         op1 = convert (integer_type_node, op1);
  1340.     }
  1341.       break;
  1342.  
  1343.     case EQ_EXPR:
  1344.     case NE_EXPR:
  1345.       /* Result of comparison is always int,
  1346.      but don't convert the args to int!  */
  1347.       result_type = integer_type_node;
  1348.       converted = 1;
  1349.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1350.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1351.     short_compare = 1;
  1352.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1353.     {
  1354.       register tree tt0 = TREE_TYPE (dt0);
  1355.       register tree tt1 = TREE_TYPE (dt1);
  1356.       /* Anything compares with void *.  void * compares with anything.
  1357.          Otherwise, the targets must be the same.  */
  1358.       if (comp_target_types (dt0, dt1))
  1359.         ;
  1360.       else if (tt0 == void_type_node)
  1361.         {
  1362.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
  1363.         warning ("ANSI C forbids comparison of `void *' with function pointer");
  1364.         }
  1365.       else if (tt1 == void_type_node)
  1366.         {
  1367.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
  1368.         warning ("ANSI C forbids comparison of `void *' with function pointer");
  1369.         }
  1370.       else
  1371.         warning ("comparison of distinct pointer types lacks a cast");
  1372.     }
  1373.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  1374.         && integer_zerop (op1))
  1375.     op1 = null_pointer_node;
  1376.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  1377.         && integer_zerop (op0))
  1378.     op0 = null_pointer_node;
  1379.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1380.     {
  1381.       if (! flag_traditional)
  1382.         warning ("comparison between pointer and integer");
  1383.       op1 = convert (TREE_TYPE (op0), op1);
  1384.     }
  1385.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  1386.     {
  1387.       if (! flag_traditional)
  1388.         warning ("comparison between pointer and integer");
  1389.       op0 = convert (TREE_TYPE (op1), op0);
  1390.     }
  1391.       else
  1392.     /* If args are not valid, clear out RESULT_TYPE
  1393.        to cause an error message later.  */
  1394.     result_type = 0;
  1395.       break;
  1396.  
  1397.     case MAX_EXPR:
  1398.     case MIN_EXPR:
  1399.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1400.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1401.     shorten = 1;
  1402.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1403.     {
  1404.       if (! comp_target_types (dt0, dt1))
  1405.         warning ("comparison of distinct pointer types lacks a cast");
  1406.       else if (pedantic 
  1407.            && TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1408.         warning ("ANSI C forbids ordered comparisons of pointers to functions");
  1409.       result_type = commontype (dt0, dt1);
  1410.     }
  1411.       break;
  1412.  
  1413.     case LE_EXPR:
  1414.     case GE_EXPR:
  1415.     case LT_EXPR:
  1416.     case GT_EXPR:
  1417.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1418.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1419.     short_compare = 1;
  1420.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1421.     {
  1422.       if (! comp_target_types (dt0, dt1))
  1423.         warning ("comparison of distinct pointer types lacks a cast");
  1424.       else if (pedantic 
  1425.            && TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1426.         warning ("ANSI C forbids ordered comparisons of pointers to functions");
  1427.       result_type = integer_type_node;
  1428.     }
  1429.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  1430.         && integer_zerop (op1))
  1431.     {
  1432.       result_type = integer_type_node;
  1433.       op1 = null_pointer_node;
  1434.       if (! flag_traditional)
  1435.         warning ("ordered comparison of pointer with integer zero");
  1436.     }
  1437.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  1438.         && integer_zerop (op0))
  1439.     {
  1440.       result_type = integer_type_node;
  1441.       op0 = null_pointer_node;
  1442.       if (pedantic)
  1443.         warning ("ordered comparison of pointer with integer zero");
  1444.     }
  1445.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1446.     {
  1447.       result_type = integer_type_node;
  1448.       if (! flag_traditional)
  1449.         warning ("comparison between pointer and integer");
  1450.       op1 = convert (TREE_TYPE (op0), op1);
  1451.     }
  1452.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  1453.     {
  1454.       result_type = integer_type_node;
  1455.       if (! flag_traditional)
  1456.         warning ("comparison between pointer and integer");
  1457.       op0 = convert (TREE_TYPE (op1), op0);
  1458.     }
  1459.       converted = 1;
  1460.       break;
  1461.     }
  1462.  
  1463.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1464.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1465.     {
  1466.       if (shorten || common || short_compare)
  1467.     result_type = commontype (dt0, dt1);
  1468.  
  1469.       /* For certain operations (which identify themselves by shorten != 0)
  1470.      if both args were extended from the same smaller type,
  1471.      do the arithmetic in that type and then extend.
  1472.  
  1473.      shorten !=0 and !=1 indicates a bitwise operation.
  1474.      For them, this optimization is safe only if
  1475.      both args are zero-extended or both are sign-extended.
  1476.      Otherwise, we might change the result.
  1477.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  1478.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  1479.  
  1480.       if (shorten)
  1481.     {
  1482.       int unsigned0, unsigned1;
  1483.       tree arg0 = get_narrower (op0, &unsigned0);
  1484.       tree arg1 = get_narrower (op1, &unsigned1);
  1485.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  1486.       int uns = TREE_UNSIGNED (result_type);
  1487.       tree type;
  1488.  
  1489.       final_type = result_type;
  1490.  
  1491.       /* Handle the case that OP0 does not *contain* a conversion
  1492.          but it *requires* conversion to FINAL_TYPE.  */
  1493.  
  1494.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  1495.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  1496.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  1497.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  1498.  
  1499.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  1500.  
  1501.       /* For bitwise operations, signedness of nominal type
  1502.          does not matter.  Consider only how operands were extended.  */
  1503.       if (shorten == -1)
  1504.         uns = unsigned0;
  1505.  
  1506.       /* Note that in all three cases below we refrain from optimizing
  1507.          an unsigned operation on sign-extended args.
  1508.          That would not be valid.  */
  1509.  
  1510.       /* Both args variable: if both extended in same way
  1511.          from same width, do it in that width.
  1512.          Do it unsigned if args were zero-extended.  */
  1513.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  1514.            < TYPE_PRECISION (result_type))
  1515.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  1516.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  1517.           && unsigned0 == unsigned1
  1518.           && (unsigned0 || !uns))
  1519.         result_type
  1520.           = signed_or_unsigned_type (unsigned0,
  1521.                      commontype (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  1522.       else if (TREE_CODE (arg0) == INTEGER_CST
  1523.            && (unsigned1 || !uns)
  1524.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  1525.                < TYPE_PRECISION (result_type))
  1526.            && (type = signed_or_unsigned_type (unsigned1,
  1527.                                TREE_TYPE (arg1)),
  1528.                int_fits_type_p (arg0, type)))
  1529.         result_type = type;
  1530.       else if (TREE_CODE (arg1) == INTEGER_CST
  1531.            && (unsigned0 || !uns)
  1532.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  1533.                < TYPE_PRECISION (result_type))
  1534.            && (type = signed_or_unsigned_type (unsigned0,
  1535.                                TREE_TYPE (arg0)),
  1536.                int_fits_type_p (arg1, type)))
  1537.         result_type = type;
  1538.     }
  1539.  
  1540.       /* Shifts can be shortened if shifting right.  */
  1541.  
  1542.       if (short_shift)
  1543.     {
  1544.       int unsigned_arg;
  1545.       tree arg0 = get_narrower (op0, &unsigned_arg);
  1546.  
  1547.       final_type = result_type;
  1548.  
  1549.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  1550.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  1551.  
  1552.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  1553.           /* If arg is sign-extended and then unsigned-shifted,
  1554.          we can simulate this with a signed shift in arg's type
  1555.          only if the extended result is at least twice as wide
  1556.          as the arg.  Otherwise, the shift could use up all the
  1557.          ones made by sign-extension and bring in zeros.
  1558.          We can't optimize that case at all, but in most machines
  1559.          it never happens because available widths are 2**N.  */
  1560.           && (!TREE_UNSIGNED (final_type)
  1561.           || unsigned_arg
  1562.           || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
  1563.         {
  1564.           /* Do an unsigned shift if the operand was zero-extended.  */
  1565.           result_type
  1566.         = signed_or_unsigned_type (unsigned_arg,
  1567.                        TREE_TYPE (arg0));
  1568.           /* Convert value-to-be-shifted to that type.  */
  1569.           if (TREE_TYPE (op0) != result_type)
  1570.         op0 = convert (result_type, op0);
  1571.           converted = 1;
  1572.         }
  1573.     }
  1574.  
  1575.       /* Comparison operations are shortened too but differently.
  1576.      They identify themselves by setting short_compare = 1.  */
  1577.  
  1578.       if (short_compare)
  1579.     {
  1580.       /* Don't write &op0, etc., because that would prevent op0
  1581.          from being kept in a register.
  1582.          Instead, make copies of the our local variables and
  1583.          pass the copies by reference, then copy them back afterward.  */
  1584.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  1585.       enum tree_code xresultcode = resultcode;
  1586.       tree val 
  1587.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  1588.       if (val != 0)
  1589.         return val;
  1590.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  1591.       resultcode = xresultcode;
  1592.     }
  1593.     }
  1594.  
  1595.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  1596.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  1597.      Then the expression will be built.
  1598.      It will be given type FINAL_TYPE if that is nonzero;
  1599.      otherwise, it will be given type RESULT_TYPE.  */
  1600.  
  1601.   if (!result_type)
  1602.     {
  1603.       binary_op_error (error_code);
  1604.       return error_mark_node;
  1605.     }
  1606.  
  1607.   if (! converted)
  1608.     {
  1609.       if (TREE_TYPE (op0) != result_type)
  1610.     op0 = convert (result_type, op0); 
  1611.       if (TREE_TYPE (op1) != result_type)
  1612.     op1 = convert (result_type, op1); 
  1613.     }
  1614.  
  1615.   {
  1616.     register tree result = build (resultcode, result_type, op0, op1);
  1617.     register tree folded;
  1618.  
  1619.     folded = fold (result);
  1620.     if (folded == result)
  1621.       TREE_LITERAL (folded) = TREE_LITERAL (op0) & TREE_LITERAL (op1);
  1622.     if (final_type != 0)
  1623.       return convert (final_type, folded);
  1624.     return folded;
  1625.   }
  1626. }
  1627.  
  1628. /* Return a tree for the sum or difference (RESULTCODE says which)
  1629.    of pointer PTROP and integer INTOP.  */
  1630.  
  1631. static tree
  1632. pointer_int_sum (resultcode, ptrop, intop)
  1633.      enum tree_code resultcode;
  1634.      register tree ptrop, intop;
  1635. {
  1636.   tree size_exp;
  1637.  
  1638.   register tree result;
  1639.   register tree folded;
  1640.  
  1641.   /* The result is a pointer of the same type that is being added.  */
  1642.  
  1643.   register tree result_type = datatype (ptrop);
  1644.  
  1645.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  1646.     {
  1647.       if (pedantic || warn_pointer_arith)
  1648.     warning ("pointer of type `void *' used in arithmetic");
  1649.       size_exp = integer_one_node;
  1650.     }
  1651.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  1652.     {
  1653.       if (pedantic || warn_pointer_arith)
  1654.     warning ("pointer to a function used in arithmetic");
  1655.       size_exp = integer_one_node;
  1656.     }
  1657.   else
  1658.     size_exp = c_sizeof (TREE_TYPE (result_type));
  1659.  
  1660.   /* If what we are about to multiply by the size of the elements
  1661.      contains a constant term, apply distributive law
  1662.      and multiply that constant term separately.
  1663.      This helps produce common subexpressions.  */
  1664.  
  1665.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  1666.       && ! TREE_LITERAL (intop)
  1667.       && TREE_LITERAL (TREE_OPERAND (intop, 1))
  1668.       && TREE_LITERAL (size_exp))
  1669.     {
  1670.       enum tree_code subcode = resultcode;
  1671.       if (TREE_CODE (intop) == MINUS_EXPR)
  1672.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  1673.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1));
  1674.       intop = TREE_OPERAND (intop, 0);
  1675.     }
  1676.  
  1677.   /* Convert the integer argument to a type the same size as a pointer
  1678.      so the multiply won't overflow spuriously.  */
  1679.  
  1680.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  1681.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  1682.  
  1683.   /* Replace the integer argument
  1684.      with a suitable product by the object size.  */
  1685.  
  1686.   intop = build_binary_op (MULT_EXPR, intop, size_exp);
  1687.  
  1688.   /* Create the sum or difference.  */
  1689.  
  1690.   result = build (resultcode, result_type, ptrop, intop);
  1691.  
  1692.   folded = fold (result);
  1693.   if (folded == result)
  1694.     TREE_LITERAL (folded) = TREE_LITERAL (ptrop) & TREE_LITERAL (intop);
  1695.   return folded;
  1696. }
  1697.  
  1698. /* Return a tree for the difference of pointers OP0 and OP1.
  1699.    The resulting tree has type int.  */
  1700.  
  1701. static tree
  1702. pointer_diff (op0, op1)
  1703.      register tree op0, op1;
  1704. {
  1705.   tree dt0 = datatype (op0);
  1706.   enum tree_code resultcode;
  1707.   register tree result, folded;
  1708.   tree restype = type_for_size (POINTER_SIZE, 0);
  1709.  
  1710.   if (pedantic)
  1711.     {
  1712.       if (TREE_CODE (TREE_TYPE (dt0)) == VOID_TYPE)
  1713.     warning ("pointer of type `void *' used in subtraction");
  1714.       if (TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1715.     warning ("pointer to a function used in subtraction");
  1716.     }
  1717.  
  1718.   /* First do the subtraction as integers;
  1719.      then drop through to build the divide operator.  */
  1720.  
  1721.   op0 = build_binary_op (MINUS_EXPR,
  1722.              convert (restype, op0), convert (restype, op1));
  1723.   op1 = c_sizeof_nowarn (TREE_TYPE (dt0));
  1724.  
  1725.   /* Create the sum or difference.  */
  1726.  
  1727.   result = build (EXACT_DIV_EXPR, restype, op0, op1);
  1728.  
  1729.   folded = fold (result);
  1730.   if (folded == result)
  1731.     TREE_LITERAL (folded) = TREE_LITERAL (op0) & TREE_LITERAL (op1);
  1732.   return folded;
  1733. }
  1734.  
  1735. /* Print an error message for invalid operands to arith operation CODE.
  1736.    NOP_EXPR is used as a special case (see truthvalue_conversion).  */
  1737.  
  1738. static void
  1739. binary_op_error (code)
  1740.      enum tree_code code;
  1741. {
  1742.   register char *opname;
  1743.   switch (code)
  1744.     {
  1745.     case NOP_EXPR:
  1746.       error ("invalid truth-value expression");
  1747.       return;
  1748.  
  1749.     case PLUS_EXPR:
  1750.       opname = "+"; break;
  1751.     case MINUS_EXPR:
  1752.       opname = "-"; break;
  1753.     case MULT_EXPR:
  1754.       opname = "*"; break;
  1755.     case MAX_EXPR:
  1756.       opname = "max"; break;
  1757.     case MIN_EXPR:
  1758.       opname = "min"; break;
  1759.     case EQ_EXPR:
  1760.       opname = "=="; break;
  1761.     case NE_EXPR:
  1762.       opname = "!="; break;
  1763.     case LE_EXPR:
  1764.       opname = "<="; break;
  1765.     case GE_EXPR:
  1766.       opname = ">="; break;
  1767.     case LT_EXPR:
  1768.       opname = "<"; break;
  1769.     case GT_EXPR:
  1770.       opname = ">"; break;
  1771.     case LSHIFT_EXPR:
  1772.       opname = "<<"; break;
  1773.     case RSHIFT_EXPR:
  1774.       opname = ">>"; break;
  1775.     case TRUNC_MOD_EXPR:
  1776.       opname = "%"; break;
  1777.     case TRUNC_DIV_EXPR:
  1778.       opname = "/"; break;
  1779.     case BIT_AND_EXPR:
  1780.       opname = "&"; break;
  1781.     case BIT_IOR_EXPR:
  1782.       opname = "|"; break;
  1783.     case TRUTH_ANDIF_EXPR:
  1784.       opname = "&&"; break;
  1785.     case TRUTH_ORIF_EXPR:
  1786.       opname = "||"; break;
  1787.     case BIT_XOR_EXPR:
  1788.       opname = "^"; break;
  1789.     }
  1790.   error ("invalid operands to binary %s", opname);
  1791. }
  1792.  
  1793. /* Subroutine of build_binary_op_nodefault, used for comparison operations.
  1794.    See if the operands have both been converted from subword integer types
  1795.    and, if so, perhaps change them both back to their original type.
  1796.  
  1797.    The arguments of this function are all pointers to local variables
  1798.    of build_binary_op_nodefault: OP0_PTR is &OP0, OP1_PTR is &OP1,
  1799.    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
  1800.  
  1801.    If this function returns nonzero, it means that the comparison has
  1802.    a constant value.  What this function returns is an expression for
  1803.    that value.  */
  1804.  
  1805. static tree
  1806. shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
  1807.      tree *op0_ptr, *op1_ptr;
  1808.      tree *restype_ptr;
  1809.      enum tree_code *rescode_ptr;
  1810. {
  1811.   register tree type;
  1812.   tree op0 = *op0_ptr;
  1813.   tree op1 = *op1_ptr;
  1814.   int unsignedp0, unsignedp1;
  1815.   int real1, real2;
  1816.   tree primop0, primop1;
  1817.   enum tree_code code = *rescode_ptr;
  1818.  
  1819.   /* Throw away any conversions to wider types
  1820.      already present in the operands.  */
  1821.  
  1822.   primop0 = get_narrower (op0, &unsignedp0);
  1823.   primop1 = get_narrower (op1, &unsignedp1);
  1824.  
  1825.   /* Handle the case that OP0 does not *contain* a conversion
  1826.      but it *requires* conversion to FINAL_TYPE.  */
  1827.  
  1828.   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
  1829.     unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
  1830.   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
  1831.     unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
  1832.  
  1833.   /* If one of the operands must be floated, we cannot optimize.  */
  1834.   real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
  1835.   real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
  1836.  
  1837.   /* If first arg is constant, swap the args (changing operation
  1838.      so value is preserved), for canonicalization.  */
  1839.  
  1840.   if (TREE_LITERAL (primop0))
  1841.     {
  1842.       register tree tem = primop0;
  1843.       register int temi = unsignedp0;
  1844.       primop0 = primop1;
  1845.       primop1 = tem;
  1846.       tem = op0;
  1847.       op0 = op1;
  1848.       op1 = tem;
  1849.       *op0_ptr = op0;
  1850.       *op1_ptr = op1;
  1851.       unsignedp0 = unsignedp1;
  1852.       unsignedp1 = temi;
  1853.       temi = real1;
  1854.       real1 = real2;
  1855.       real2 = temi;
  1856.  
  1857.       switch (code)
  1858.     {
  1859.     case LT_EXPR:
  1860.       code = GT_EXPR;
  1861.       break;
  1862.     case GT_EXPR:
  1863.       code = LT_EXPR;
  1864.       break;
  1865.     case LE_EXPR:
  1866.       code = GE_EXPR;
  1867.       break;
  1868.     case GE_EXPR:
  1869.       code = LE_EXPR;
  1870.       break;
  1871.     }
  1872.       *rescode_ptr = code;
  1873.     }
  1874.  
  1875.   /* If comparing an integer against a constant more bits wide,
  1876.      maybe we can deduce a value of 1 or 0 independent of the data.
  1877.      Or else truncate the constant now
  1878.      rather than extend the variable at run time.
  1879.  
  1880.      This is only interesting if the constant is the wider arg.
  1881.      Also, it is not safe if the constant is unsigned and the
  1882.      variable arg is signed, since in this case the variable
  1883.      would be sign-extended and then regarded as unsigned.
  1884.      Our technique fails in this case because the lowest/highest
  1885.      possible unsigned results don't follow naturally from the
  1886.      lowest/highest possible values of the variable operand.
  1887.      For just EQ_EXPR and NE_EXPR there is another technique that
  1888.      could be used: see if the constant can be faithfully represented
  1889.      in the other operand's type, by truncating it and reextending it
  1890.      and see if that preserves the constant's value.  */
  1891.  
  1892.   if (!real1 && !real2
  1893.       && TREE_CODE (primop1) == INTEGER_CST
  1894.       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
  1895.     {
  1896.       int min_gt, max_gt, min_lt, max_lt;
  1897.       tree maxval, minval;
  1898.       /* 1 if comparison is nominally unsigned.  */
  1899.       int unsignedp = TREE_UNSIGNED (*restype_ptr);
  1900.       tree val;
  1901.  
  1902.       type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
  1903.  
  1904.       maxval = TYPE_MAX_VALUE (type);
  1905.       minval = TYPE_MIN_VALUE (type);
  1906.  
  1907.       if (unsignedp && !unsignedp0)
  1908.     *restype_ptr = signed_type (*restype_ptr);
  1909.  
  1910.       if (TREE_TYPE (primop1) != *restype_ptr)
  1911.     primop1 = convert (*restype_ptr, primop1);
  1912.       if (type != *restype_ptr)
  1913.     {
  1914.       minval = convert (*restype_ptr, minval);
  1915.       maxval = convert (*restype_ptr, maxval);
  1916.     }
  1917.  
  1918.       if (unsignedp && unsignedp0)
  1919.     {
  1920.       min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
  1921.       max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
  1922.       min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
  1923.       max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
  1924.     }
  1925.       else
  1926.     {
  1927.       min_gt = INT_CST_LT (primop1, minval);
  1928.       max_gt = INT_CST_LT (primop1, maxval);
  1929.       min_lt = INT_CST_LT (minval, primop1);
  1930.       max_lt = INT_CST_LT (maxval, primop1);
  1931.     }
  1932.  
  1933.       val = 0;
  1934.       /* This used to be a switch, but Genix compiler can't handle that.  */
  1935.       if (code == NE_EXPR)
  1936.     {
  1937.       if (max_lt || min_gt)
  1938.         val = integer_one_node;
  1939.     }
  1940.       else if (code == EQ_EXPR)
  1941.     {
  1942.       if (max_lt || min_gt)
  1943.         val = integer_zero_node;
  1944.     }
  1945.       else if (code == LT_EXPR)
  1946.     {
  1947.       if (max_lt)
  1948.         val = integer_one_node;
  1949.       if (!min_lt)
  1950.         val = integer_zero_node;
  1951.     }
  1952.       else if (code == GT_EXPR)
  1953.     {
  1954.       if (min_gt)
  1955.         val = integer_one_node;
  1956.       if (!max_gt)
  1957.         val = integer_zero_node;
  1958.     }
  1959.       else if (code == LE_EXPR)
  1960.     {
  1961.       if (!max_gt)
  1962.         val = integer_one_node;
  1963.       if (min_gt)
  1964.         val = integer_zero_node;
  1965.     }
  1966.       else if (code == GE_EXPR)
  1967.     {
  1968.       if (!min_lt)
  1969.         val = integer_one_node;
  1970.       if (max_lt)
  1971.         val = integer_zero_node;
  1972.     }
  1973.  
  1974.       /* If primop0 was sign-extended and unsigned comparison specd,
  1975.      we did a signed comparison above using the signed type bounds.
  1976.      But the comparison we output must be unsigned.
  1977.  
  1978.      Also, for inequalities, VAL is no good; but if the signed
  1979.      comparison had *any* fixed result, it follows that the
  1980.      unsigned comparison just tests the sign in reverse
  1981.      (positive values are LE, negative ones GE).
  1982.      So we can generate an unsigned comparison
  1983.      against an extreme value of the signed type.  */
  1984.  
  1985.       if (unsignedp && !unsignedp0)
  1986.     {
  1987.       if (val != 0)
  1988.         switch (code)
  1989.           {
  1990.           case LT_EXPR:
  1991.           case GE_EXPR:
  1992.         primop1 = TYPE_MIN_VALUE (type);
  1993.         val = 0;
  1994.         break;
  1995.  
  1996.           case LE_EXPR:
  1997.           case GT_EXPR:
  1998.         primop1 = TYPE_MAX_VALUE (type);
  1999.         val = 0;
  2000.         break;
  2001.           }
  2002.       type = unsigned_type (type);
  2003.     }
  2004.  
  2005.       if (max_lt && !unsignedp0)
  2006.     {
  2007.       /* This is the case of (char)x >?< 0x80, which people used to use
  2008.          expecting old C compilers to change the 0x80 into -0x80.  */
  2009.       if (val == integer_zero_node)
  2010.         warning ("comparison is always 0 due to limited range of data type");
  2011.       if (val == integer_one_node)
  2012.         warning ("comparison is always 1 due to limited range of data type");
  2013.     }
  2014.  
  2015.       if (val != 0)
  2016.     {
  2017.       /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
  2018.       if (TREE_VOLATILE (primop0))
  2019.         return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
  2020.       return val;
  2021.     }
  2022.  
  2023.       /* Value is not predetermined, but do the comparison
  2024.      in the type of the operand that is not constant.
  2025.      TYPE is already properly set.  */
  2026.     }
  2027.   else if (real1 && real2
  2028.        && TYPE_PRECISION (TREE_TYPE (primop0)) == TYPE_PRECISION (TREE_TYPE (primop1)))
  2029.     type = TREE_TYPE (primop0);
  2030.  
  2031.   /* If args' natural types are both narrower than nominal type
  2032.      and both extend in the same manner, compare them
  2033.      in the type of the wider arg.
  2034.      Otherwise must actually extend both to the nominal
  2035.      common type lest different ways of extending
  2036.      alter the result.
  2037.      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
  2038.  
  2039.   else if (unsignedp0 == unsignedp1 && real1 == real2
  2040.        && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
  2041.        && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
  2042.     {
  2043.       type = commontype (TREE_TYPE (primop0), TREE_TYPE (primop1));
  2044.       type = signed_or_unsigned_type (unsignedp0
  2045.                       || TREE_UNSIGNED (*restype_ptr),
  2046.                       type);
  2047.       /* Make sure shorter operand is extended the right way
  2048.      to match the longer operand.  */
  2049.       primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
  2050.              primop0);
  2051.       primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
  2052.              primop1);
  2053.     }
  2054.   else
  2055.     {
  2056.       /* Here we must do the comparison on the nominal type
  2057.      using the args exactly as we received them.  */
  2058.       type = *restype_ptr;
  2059.       primop0 = op0;
  2060.       primop1 = op1;
  2061.     }
  2062.  
  2063.   *op0_ptr = convert (type, primop0);
  2064.   *op1_ptr = convert (type, primop1);
  2065.  
  2066.   *restype_ptr = integer_type_node;
  2067.  
  2068.   return 0;
  2069. }
  2070.  
  2071. /* Construct and perhaps optimize a tree representation
  2072.    for a unary operation.  CODE, a tree_code, specifies the operation
  2073.    and XARG is the operand.  NOCONVERT nonzero suppresses
  2074.    the default promotions (such as from short to int).  */
  2075.  
  2076. tree
  2077. build_unary_op (code, xarg, noconvert)
  2078.      enum tree_code code;
  2079.      tree xarg;
  2080.      int noconvert;
  2081. {
  2082.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  2083.   register tree arg = xarg;
  2084.   register tree argtype = 0;
  2085.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  2086.   char *errstring = NULL;
  2087.   tree val;
  2088.  
  2089.   if (typecode == ERROR_MARK)
  2090.     return error_mark_node;
  2091.   if (typecode == ENUMERAL_TYPE)
  2092.     typecode = INTEGER_TYPE;
  2093.  
  2094.   switch (code)
  2095.     {
  2096.     case CONVERT_EXPR:
  2097.       /* This is used for unary plus, because a CONVERT_EXPR
  2098.      is enough to prevent anybody from looking inside for
  2099.      associativity, but won't generate any code.  */
  2100.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  2101.         errstring = "wrong type argument to unary plus";
  2102.       else if (!noconvert)
  2103.     arg = default_conversion (arg);
  2104.       break;
  2105.  
  2106.     case NEGATE_EXPR:
  2107.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  2108.         errstring = "wrong type argument to unary minus";
  2109.       else if (!noconvert)
  2110.     arg = default_conversion (arg);
  2111.       break;
  2112.  
  2113.     case BIT_NOT_EXPR:
  2114.       if (typecode != INTEGER_TYPE)
  2115.         errstring = "wrong type argument to bit-complement";
  2116.       else if (!noconvert)
  2117.     arg = default_conversion (arg);
  2118.       break;
  2119.  
  2120.     case ABS_EXPR:
  2121.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  2122.         errstring = "wrong type argument to abs";
  2123.       else if (!noconvert)
  2124.     arg = default_conversion (arg);
  2125.       break;
  2126.  
  2127.     case TRUTH_NOT_EXPR:
  2128.       if (typecode != INTEGER_TYPE
  2129.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  2130.       /* This will convert to a pointer.  */
  2131.       && typecode != ARRAY_TYPE)
  2132.     {
  2133.       errstring = "wrong type argument to unary exclamation mark";
  2134.       break;
  2135.     }
  2136.       arg = truthvalue_conversion (arg);
  2137.       val = invert_truthvalue (arg);
  2138.       if (val) return val;
  2139.       break;
  2140.  
  2141.     case NOP_EXPR:
  2142.       break;
  2143.       
  2144.     case PREINCREMENT_EXPR:
  2145.     case POSTINCREMENT_EXPR:
  2146.     case PREDECREMENT_EXPR:
  2147.     case POSTDECREMENT_EXPR:
  2148.       /* Handle complex lvalues (when permitted)
  2149.      by reduction to simpler cases.  */
  2150.  
  2151.       val = unary_complex_lvalue (code, arg);
  2152.       if (val != 0)
  2153.     return val;
  2154.  
  2155.       /* Report invalid types.  */
  2156.  
  2157.       if (typecode != POINTER_TYPE
  2158.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  2159.     {
  2160.       if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  2161.         errstring ="wrong type argument to increment";
  2162.       else
  2163.         errstring ="wrong type argument to decrement";
  2164.       break;
  2165.     }
  2166.  
  2167.       /* Report something read-only.  */
  2168.  
  2169.       if (TREE_READONLY (arg))
  2170.     readonly_warning (arg, 
  2171.               ((code == PREINCREMENT_EXPR
  2172.                 || code == POSTINCREMENT_EXPR)
  2173.                ? "increment" : "decrement"));
  2174.  
  2175.       {
  2176.     register tree inc;
  2177.     tree result_type = TREE_TYPE (arg);
  2178.  
  2179.     arg = get_unwidened (arg, 0);
  2180.     argtype = TREE_TYPE (arg);
  2181.  
  2182.     /* Compute the increment.  */
  2183.  
  2184.     if (typecode == POINTER_TYPE)
  2185.       {
  2186.         if (pedantic && (TREE_CODE (argtype) == FUNCTION_TYPE
  2187.                  || TREE_CODE (argtype) == VOID_TYPE))
  2188.           warning ("wrong type argument to %s",
  2189.                ((code == PREINCREMENT_EXPR
  2190.              || code == POSTINCREMENT_EXPR)
  2191.             ? "increment" : "decrement"));
  2192.         inc = c_sizeof_nowarn (TREE_TYPE (argtype));
  2193.       }
  2194.     else
  2195.       inc = integer_one_node;
  2196.  
  2197.     inc = convert (argtype, inc);
  2198.  
  2199.     /* Handle incrementing a cast-expression.  */
  2200.  
  2201.     if (!pedantic)
  2202.       switch (TREE_CODE (arg))
  2203.         {
  2204.         case NOP_EXPR:
  2205.         case CONVERT_EXPR:
  2206.         case FLOAT_EXPR:
  2207.         case FIX_TRUNC_EXPR:
  2208.         case FIX_FLOOR_EXPR:
  2209.         case FIX_ROUND_EXPR:
  2210.         case FIX_CEIL_EXPR:
  2211.           {
  2212.         tree incremented, modify, value;
  2213.         arg = stabilize_reference (arg);
  2214.         if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  2215.           value = arg;
  2216.         else
  2217.           value = save_expr (arg);
  2218.         incremented = build (((code == PREINCREMENT_EXPR
  2219.                        || code == POSTINCREMENT_EXPR)
  2220.                       ? PLUS_EXPR : MINUS_EXPR),
  2221.                      argtype, value, inc);
  2222.         TREE_VOLATILE (incremented) = 1;
  2223.         modify = build_modify_expr (arg, NOP_EXPR, incremented);
  2224.         return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  2225.           }
  2226.         }
  2227.  
  2228.     /* Complain about anything else that is not a true lvalue.  */
  2229.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  2230.                     || code == POSTINCREMENT_EXPR)
  2231.                    ? "increment" : "decrement")))
  2232.       return error_mark_node;
  2233.  
  2234.     val = build (code, TREE_TYPE (arg), arg, inc);
  2235.     TREE_VOLATILE (val) = 1;
  2236.     return convert (result_type, val);
  2237.       }
  2238.  
  2239.     case ADDR_EXPR:
  2240.       /* Note that this operation never does default_conversion
  2241.      regardless of NOCONVERT.  */
  2242.  
  2243.       /* Let &* cancel out to simplify resulting code.  */
  2244.       if (TREE_CODE (arg) == INDIRECT_REF)
  2245.     return TREE_OPERAND (arg, 0);
  2246.  
  2247.       /* For &x[y], return x+y */
  2248.       if (TREE_CODE (arg) == ARRAY_REF)
  2249.     {
  2250.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  2251.         return error_mark_node;
  2252.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  2253.                   TREE_OPERAND (arg, 1));
  2254.     }
  2255.  
  2256.       /* Handle complex lvalues (when permitted)
  2257.      by reduction to simpler cases.  */
  2258.       val = unary_complex_lvalue (code, arg);
  2259.       if (val != 0)
  2260.     return val;
  2261.  
  2262.       /* Address of a cast is just a cast of the address
  2263.      of the operand of the cast.  */
  2264.       switch (TREE_CODE (arg))
  2265.     {
  2266.     case NOP_EXPR:
  2267.     case CONVERT_EXPR:
  2268.     case FLOAT_EXPR:
  2269.     case FIX_TRUNC_EXPR:
  2270.     case FIX_FLOOR_EXPR:
  2271.     case FIX_ROUND_EXPR:
  2272.     case FIX_CEIL_EXPR:
  2273.       if (pedantic)
  2274.         warning ("ANSI C forbids the address of a cast expression");
  2275.       return convert (build_pointer_type (TREE_TYPE (arg)),
  2276.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
  2277.                       0));
  2278.     }
  2279.  
  2280.       /* Allow the address of a constructor if all the elements
  2281.      are constant.  */
  2282.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_LITERAL (arg))
  2283.     ;
  2284.       /* Anything not already handled and not a true memory reference
  2285.      is an error.  */
  2286.       else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
  2287.     return error_mark_node;
  2288.  
  2289.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  2290.       argtype = TREE_TYPE (arg);
  2291.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  2292.     argtype = build_type_variant (argtype,
  2293.                       TREE_READONLY (arg),
  2294.                       TREE_THIS_VOLATILE (arg));
  2295.  
  2296.       argtype = build_pointer_type (argtype);
  2297.  
  2298.       if (mark_addressable (arg) == 0)
  2299.     return error_mark_node;
  2300.  
  2301.       {
  2302.     tree addr;
  2303.  
  2304.     if (TREE_CODE (arg) == COMPONENT_REF)
  2305.       {
  2306.         tree field = TREE_OPERAND (arg, 1);
  2307.  
  2308.         addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  2309.  
  2310.         if (TREE_PACKED (field))
  2311.           {
  2312.         error ("attempt to take address of bit-field structure member `%s'",
  2313.                IDENTIFIER_POINTER (DECL_NAME (field)));
  2314.         return error_mark_node;
  2315.           }
  2316.  
  2317.         addr = convert (argtype, addr);
  2318.  
  2319.         if (DECL_OFFSET (field) != 0)
  2320.           {
  2321.         tree offset = build_int_2 ((DECL_OFFSET (field)
  2322.                         / BITS_PER_UNIT),
  2323.                        0);
  2324.         TREE_TYPE (offset) = argtype;
  2325.         addr = fold (build (PLUS_EXPR, argtype, addr, offset));
  2326.           }
  2327.       }
  2328.     else
  2329.       addr = build (code, argtype, arg);
  2330.  
  2331.     /* Address of a static or external variable or
  2332.        function counts as a constant */
  2333.     TREE_LITERAL (addr) = staticp (arg);
  2334.     return addr;
  2335.       }
  2336.     }
  2337.  
  2338.   if (!errstring)
  2339.     {
  2340.       if (argtype == 0)
  2341.     argtype = TREE_TYPE (arg);
  2342.       return fold (build (code, argtype, arg));
  2343.     }
  2344.  
  2345.   error (errstring);
  2346.   return error_mark_node;
  2347. }
  2348.  
  2349. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  2350.    convert ARG with the same conversions in the same order
  2351.    and return the result.  */
  2352.  
  2353. static tree
  2354. convert_sequence (conversions, arg)
  2355.      tree conversions;
  2356.      tree arg;
  2357. {
  2358.   switch (TREE_CODE (conversions))
  2359.     {
  2360.     case NOP_EXPR:
  2361.     case CONVERT_EXPR:
  2362.     case FLOAT_EXPR:
  2363.     case FIX_TRUNC_EXPR:
  2364.     case FIX_FLOOR_EXPR:
  2365.     case FIX_ROUND_EXPR:
  2366.     case FIX_CEIL_EXPR:
  2367.       return convert (TREE_TYPE (conversions),
  2368.               convert_sequence (TREE_OPERAND (conversions, 0),
  2369.                     arg));
  2370.  
  2371.     default:
  2372.       return arg;
  2373.     }
  2374. }
  2375.  
  2376. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  2377.    for certain kinds of expressions which are not really lvalues
  2378.    but which we can accept as lvalues.
  2379.  
  2380.    If ARG is not a kind of expression we can handle, return zero.  */
  2381.    
  2382. static tree
  2383. unary_complex_lvalue (code, arg)
  2384.      enum tree_code code;
  2385.      tree arg;
  2386. {
  2387.   if (pedantic)
  2388.     return 0;
  2389.  
  2390.   /* Handle (a, b) used as an "lvalue".  */
  2391.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  2392.     {
  2393.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  2394.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  2395.             TREE_OPERAND (arg, 0), real_result);
  2396.     }
  2397.  
  2398.   /* Handle (a ? b : c) used as an "lvalue".  */
  2399.   if (TREE_CODE (arg) == COND_EXPR)
  2400.     return (build_conditional_expr
  2401.         (TREE_OPERAND (arg, 0),
  2402.          build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  2403.          build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  2404.  
  2405.   return 0;
  2406. }
  2407.  
  2408. /* Warn about storing in something that is `const'.  */
  2409.  
  2410. void
  2411. readonly_warning (arg, string)
  2412.      tree arg;
  2413.      char *string;
  2414. {
  2415.   char buf[80];
  2416.   strcpy (buf, string);
  2417.  
  2418.   if (TREE_CODE (arg) == COMPONENT_REF)
  2419.     {
  2420.       if (TREE_READONLY (TREE_OPERAND (arg, 0)))
  2421.     readonly_warning (TREE_OPERAND (arg, 0), string);
  2422.       else
  2423.     {
  2424.       strcat (buf, " of read-only member `%s'");
  2425.       warning (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
  2426.     }
  2427.     }
  2428.   else if (TREE_CODE (arg) == VAR_DECL)
  2429.     {
  2430.       strcat (buf, " of read-only variable `%s'");
  2431.       warning (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  2432.     }
  2433.   else
  2434.     {
  2435.       warning ("%s of read-only location", buf);
  2436.     }
  2437. }
  2438.  
  2439. /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
  2440.    or validate its data type for an `if' or `while' statement or ?..: exp.
  2441.  
  2442.    This preparation consists of taking the ordinary
  2443.    representation of an expression expr and producing a valid tree
  2444.    boolean expression describing whether expr is nonzero.  We could
  2445.    simply always do build_binary_op (NE_EXPR, expr, integer_zero_node),
  2446.    but we optimize comparisons, &&, ||, and !  */
  2447.  
  2448. tree
  2449. truthvalue_conversion (expr)
  2450.      tree expr;
  2451. {
  2452.   register enum tree_code form;
  2453.  
  2454.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2455.      Strip such NOP_EXPRs, since EXPR is being used in non-lvalue context.  */
  2456.   if (TREE_CODE (expr) == NOP_EXPR
  2457.       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
  2458.     expr = TREE_OPERAND (expr, 0);
  2459.  
  2460.   form = TREE_CODE (expr);
  2461.  
  2462.   if (form == EQ_EXPR && integer_zerop (TREE_OPERAND (expr, 1)))
  2463.     return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0);
  2464.  
  2465.   /* A one-bit unsigned bit-field is already acceptable.  */
  2466.   if (form == COMPONENT_REF
  2467.       && 1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
  2468.       && 1 == DECL_SIZE_UNIT (TREE_OPERAND (expr, 1))
  2469.       && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
  2470.     return expr;
  2471.  
  2472.   if (form == TRUTH_ANDIF_EXPR || form == TRUTH_ORIF_EXPR
  2473.       || form == TRUTH_AND_EXPR || form == TRUTH_OR_EXPR
  2474.       || form == TRUTH_NOT_EXPR
  2475.       || form == EQ_EXPR || form == NE_EXPR
  2476.       || form == LE_EXPR || form == GE_EXPR
  2477.       || form == LT_EXPR || form == GT_EXPR
  2478.       || form == ERROR_MARK)
  2479.     return expr;
  2480.  
  2481.   /* Unary minus has no effect on whether its argument is nonzero.  */
  2482.   if (form == NEGATE_EXPR)
  2483.     return truthvalue_conversion (TREE_OPERAND (expr, 0));
  2484.  
  2485.   /* Distribute the conversion into the arms of a COND_EXPR.  */
  2486.   if (form == COND_EXPR)
  2487.     return build (COND_EXPR, TREE_TYPE (expr),
  2488.           TREE_OPERAND (expr, 0),
  2489.           truthvalue_conversion (TREE_OPERAND (expr, 1)),
  2490.           truthvalue_conversion (TREE_OPERAND (expr, 2)));
  2491.  
  2492.   /* Sign-extension and zero-extension has no effect.  */
  2493.   if (form == NOP_EXPR
  2494.       && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
  2495.       && (TYPE_PRECISION (TREE_TYPE (expr))
  2496.       > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))))
  2497.     return truthvalue_conversion (TREE_OPERAND (expr, 0));
  2498.  
  2499.   return build_binary_op_nodefault (NE_EXPR, default_conversion (expr),
  2500.                     integer_zero_node, NOP_EXPR);
  2501. }
  2502.  
  2503. /* Return a simplified tree node for the truth-negation of ARG
  2504.    (perhaps by altering ARG).
  2505.    If it can't be simplified, return 0.  */
  2506.  
  2507. static tree
  2508. invert_truthvalue (arg)
  2509.      tree arg;
  2510. {
  2511.   switch (TREE_CODE (arg))
  2512.     {
  2513.     case NE_EXPR:
  2514.       TREE_SET_CODE (arg, EQ_EXPR);
  2515.       return arg;
  2516.  
  2517.     case EQ_EXPR:
  2518.       TREE_SET_CODE (arg, NE_EXPR);
  2519.       return arg;
  2520.  
  2521.     case GE_EXPR:
  2522.       TREE_SET_CODE (arg, LT_EXPR);
  2523.       return arg;
  2524.  
  2525.     case GT_EXPR:
  2526.       TREE_SET_CODE (arg, LE_EXPR);
  2527.       return arg;
  2528.  
  2529.     case LE_EXPR:
  2530.       TREE_SET_CODE (arg, GT_EXPR);
  2531.       return arg;
  2532.  
  2533.     case LT_EXPR:
  2534.       TREE_SET_CODE (arg, GE_EXPR);
  2535.       return arg;
  2536.  
  2537.     case TRUTH_AND_EXPR:
  2538.       return build (TRUTH_OR_EXPR, TREE_TYPE (arg),
  2539.             build_unary_op (TRUTH_NOT_EXPR,
  2540.                     TREE_OPERAND (arg, 0), 0),
  2541.             build_unary_op (TRUTH_NOT_EXPR,
  2542.                     TREE_OPERAND (arg, 1), 0));
  2543.  
  2544.     case TRUTH_OR_EXPR:
  2545.       return build (TRUTH_AND_EXPR, TREE_TYPE (arg),
  2546.             build_unary_op (TRUTH_NOT_EXPR,
  2547.                     TREE_OPERAND (arg, 0), 0),
  2548.             build_unary_op (TRUTH_NOT_EXPR,
  2549.                     TREE_OPERAND (arg, 1), 0));
  2550.  
  2551.     case TRUTH_ANDIF_EXPR:
  2552.       return build (TRUTH_ORIF_EXPR, TREE_TYPE (arg),
  2553.             build_unary_op (TRUTH_NOT_EXPR,
  2554.                     TREE_OPERAND (arg, 0), 0),
  2555.             build_unary_op (TRUTH_NOT_EXPR,
  2556.                     TREE_OPERAND (arg, 1), 0));
  2557.  
  2558.     case TRUTH_ORIF_EXPR:
  2559.       return build (TRUTH_ANDIF_EXPR, TREE_TYPE (arg),
  2560.             build_unary_op (TRUTH_NOT_EXPR,
  2561.                     TREE_OPERAND (arg, 0), 0),
  2562.             build_unary_op (TRUTH_NOT_EXPR,
  2563.                     TREE_OPERAND (arg, 1), 0));
  2564.  
  2565.     case TRUTH_NOT_EXPR:
  2566.       return TREE_OPERAND (arg, 0);
  2567.     }
  2568.   return 0;
  2569. }
  2570.  
  2571. /* Mark EXP saying that we need to be able to take the
  2572.    address of it; it should not be allocated in a register.
  2573.    Value is 1 if successful.  */
  2574.  
  2575. int
  2576. mark_addressable (exp)
  2577.      tree exp;
  2578. {
  2579.   register tree x = exp;
  2580.   while (1)
  2581.     switch (TREE_CODE (x))
  2582.       {
  2583.       case ADDR_EXPR:
  2584.       case COMPONENT_REF:
  2585.       case ARRAY_REF:
  2586.     x = TREE_OPERAND (x, 0);
  2587.     break;
  2588.  
  2589.       case VAR_DECL:
  2590.       case CONST_DECL:
  2591.       case PARM_DECL:
  2592.       case RESULT_DECL:
  2593.     if (TREE_REGDECL (x) && !TREE_ADDRESSABLE (x))
  2594.       {
  2595.         if (TREE_PUBLIC (x))
  2596.           {
  2597.         error ("address of global register variable `%s' requested",
  2598.                IDENTIFIER_POINTER (DECL_NAME (x)));
  2599.         return 0;
  2600.           }
  2601.         warning ("address of register variable `%s' requested",
  2602.              IDENTIFIER_POINTER (DECL_NAME (x)));
  2603.       }
  2604.     put_var_into_stack (x);
  2605.  
  2606.     /* drops in */
  2607.       case FUNCTION_DECL:
  2608.     TREE_ADDRESSABLE (x) = 1;
  2609.     TREE_ADDRESSABLE (DECL_NAME (x)) = 1;
  2610.  
  2611.       default:
  2612.     return 1;
  2613.     }
  2614. }
  2615.  
  2616. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  2617.  
  2618. tree
  2619. build_conditional_expr (ifexp, op1, op2)
  2620.      tree ifexp, op1, op2;
  2621. {
  2622.   register tree type1;
  2623.   register tree type2;
  2624.   register enum tree_code code1;
  2625.   register enum tree_code code2;
  2626.   register tree result_type = NULL;
  2627.  
  2628.   /* If second operand is omitted, it is the same as the first one;
  2629.      make sure it is calculated only once.  */
  2630.   if (op1 == 0)
  2631.     {
  2632.       if (pedantic)
  2633.     warning ("ANSI C forbids omitting the middle term of a ?: expression");
  2634.       ifexp = op1 = save_expr (ifexp);
  2635.     }
  2636.  
  2637.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  2638.  
  2639.   if (TREE_CODE (ifexp) == ERROR_MARK
  2640.       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
  2641.       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
  2642.     return error_mark_node;
  2643.  
  2644.   /* Don't promote the operands separately if they promote
  2645.      the same way.  Return the unpromoted type and let the combined
  2646.      value get promoted if necessary.  */
  2647.  
  2648.   if (TREE_TYPE (op1) == TREE_TYPE (op2)
  2649.       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
  2650.       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
  2651.       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
  2652.     {
  2653.       if (TREE_LITERAL (ifexp)
  2654.       && (TREE_CODE (ifexp) == INTEGER_CST
  2655.           || TREE_CODE (ifexp) == ADDR_EXPR))
  2656.     return (integer_zerop (ifexp) ? op2 : op1);
  2657.  
  2658.       return build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2);
  2659.     }
  2660.  
  2661.   /* They don't match; promote them both and then try to reconcile them.  */
  2662.  
  2663.   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
  2664.     op1 = default_conversion (op1);
  2665.   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
  2666.     op2 = default_conversion (op2);
  2667.  
  2668.   type1 = TREE_TYPE (op1);
  2669.   code1 = TREE_CODE (type1);
  2670.   type2 = TREE_TYPE (op2);
  2671.   code2 = TREE_CODE (type2);
  2672.       
  2673.   /* Quickly detect the usual case where op1 and op2 have the same type
  2674.      after promotion.  */
  2675.   if (type1 == type2)
  2676.     result_type = type1;
  2677.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  2678.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  2679.     {
  2680.       result_type = commontype (type1, type2);
  2681.     }
  2682.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  2683.     {
  2684.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  2685.     warning ("ANSI C forbids conditional expr with only one void side");
  2686.       result_type = void_type_node;
  2687.     }
  2688.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  2689.     {
  2690.       if (comp_target_types (type1, type2))
  2691.     result_type = commontype (type1, type2);
  2692.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  2693.     {
  2694.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  2695.         warning ("ANSI C forbids conditional expr between `void *' and function pointer");
  2696.       result_type = qualify_type (type1, type2);
  2697.     }
  2698.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  2699.     {
  2700.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  2701.         warning ("ANSI C forbids conditional expr between `void *' and function pointer");
  2702.       result_type = qualify_type (type2, type1);
  2703.     }
  2704.       else
  2705.     {
  2706.       warning ("pointer type mismatch in conditional expression");
  2707.       result_type = build_pointer_type (void_type_node);
  2708.     }
  2709.     }
  2710.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  2711.     {
  2712.       if (!integer_zerop (op2))
  2713.     warning ("pointer/integer type mismatch in conditional expression");
  2714.       else
  2715.     {
  2716.       op2 = null_pointer_node;
  2717.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  2718.         warning ("ANSI C forbids conditional expr between 0 and function pointer");
  2719.     }
  2720.       result_type = type1;
  2721.     }
  2722.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2723.     {
  2724.       if (!integer_zerop (op1))
  2725.     warning ("pointer/integer type mismatch in conditional expression");
  2726.       else
  2727.     {
  2728.       op1 = null_pointer_node;
  2729.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  2730.         warning ("ANSI C forbids conditional expr between 0 and function pointer");
  2731.     }
  2732.       result_type = type2;
  2733.     }
  2734.  
  2735.   if (!result_type)
  2736.     {
  2737.       if (flag_cond_mismatch)
  2738.     result_type = void_type_node;
  2739.       else
  2740.     {
  2741.       error ("type mismatch in conditional expression");
  2742.       return error_mark_node;
  2743.     }
  2744.     }
  2745.  
  2746.   if (result_type != TREE_TYPE (op1))
  2747.     op1 = convert (result_type, op1);
  2748.   if (result_type != TREE_TYPE (op2))
  2749.     op2 = convert (result_type, op2);
  2750.     
  2751. #if 0
  2752.   if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
  2753.     {
  2754.       result_type = TREE_TYPE (op1);
  2755.       if (TREE_LITERAL (ifexp))
  2756.     return (integer_zerop (ifexp) ? op2 : op1);
  2757.  
  2758.       if (TYPE_MODE (result_type) == BLKmode)
  2759.     {
  2760.       register tree tempvar
  2761.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  2762.       register tree xop1 = build_modify_expr (tempvar, op1);
  2763.       register tree xop2 = build_modify_expr (tempvar, op2);
  2764.       register tree result = build (COND_EXPR, result_type,
  2765.                     ifexp, xop1, xop2);
  2766.  
  2767.       layout_decl (tempvar);
  2768.       /* No way to handle variable-sized objects here.
  2769.          I fear that the entire handling of BLKmode conditional exprs
  2770.          needs to be redone.  */
  2771.       if (! TREE_LITERAL (DECL_SIZE (tempvar)))
  2772.         abort ();
  2773.       DECL_RTL (tempvar)
  2774.         = assign_stack_local (DECL_MODE (tempvar),
  2775.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  2776.                    * DECL_SIZE_UNIT (tempvar)
  2777.                    + BITS_PER_UNIT - 1)
  2778.                   / BITS_PER_UNIT);
  2779.  
  2780.       TREE_VOLATILE (result)
  2781.         = TREE_VOLATILE (ifexp) | TREE_VOLATILE (op1)
  2782.           | TREE_VOLATILE (op2);
  2783.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  2784.     }
  2785.     }
  2786. #endif /* 0 */
  2787.  
  2788.   if (TREE_CODE (ifexp) == INTEGER_CST)
  2789.     return (integer_zerop (ifexp) ? op2 : op1);
  2790.  
  2791.   return build (COND_EXPR, result_type, ifexp, op1, op2);
  2792. }
  2793.  
  2794. /* Given a list of expressions, return a compound expression
  2795.    that performs them all and returns the value of the last of them.  */
  2796.  
  2797. tree
  2798. build_compound_expr (list)
  2799.      tree list;
  2800. {
  2801.   register tree rest;
  2802.  
  2803.   if (TREE_CHAIN (list) == 0)
  2804.     {
  2805.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2806.      Strip such NOP_EXPRs, since LIST is used in non-lvalue context.  */
  2807.       if (TREE_CODE (list) == NOP_EXPR
  2808.       && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
  2809.     list = TREE_OPERAND (list, 0);
  2810.  
  2811.       return TREE_VALUE (list);
  2812.     }
  2813.  
  2814.   rest = build_compound_expr (TREE_CHAIN (list));
  2815.  
  2816.   /* This is patched out so that sizeof (0, array) is distinguishable from
  2817.      sizeof array.  */
  2818. #if 0
  2819.   if (! TREE_VOLATILE (TREE_VALUE (list)))
  2820.     return rest;
  2821. #endif
  2822.  
  2823.   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
  2824. }
  2825.  
  2826. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  2827.  
  2828. tree
  2829. build_c_cast (type, expr)
  2830.      register tree type;
  2831.      tree expr;
  2832. {
  2833.   register tree value = expr;
  2834.   
  2835.   if (type == error_mark_node || expr == error_mark_node)
  2836.     return error_mark_node;
  2837.   type = TYPE_MAIN_VARIANT (type);
  2838.  
  2839.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2840.      Strip such NOP_EXPRs, since VALUE is being used in non-lvalue context.  */
  2841.   if (TREE_CODE (value) == NOP_EXPR
  2842.       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  2843.     value = TREE_OPERAND (value, 0);
  2844.  
  2845.   if (type == TREE_TYPE (value))
  2846.     {
  2847.       if (pedantic)
  2848.     {
  2849.       if (TREE_CODE (type) == RECORD_TYPE
  2850.           || TREE_CODE (type) == UNION_TYPE)
  2851.         warning ("ANSI C forbids casting nonscalar to the same type");
  2852.     }
  2853.     }
  2854.   else
  2855.     {
  2856.       tree otype;
  2857.       value = default_conversion (value);
  2858.       otype = TREE_TYPE (value);
  2859.  
  2860.       /* Optionally warn about potentially worrysome casts.  */
  2861.  
  2862.       if (warn_cast_qual
  2863.       && TREE_CODE (type) == POINTER_TYPE
  2864.       && TREE_CODE (otype) == POINTER_TYPE)
  2865.     {
  2866.       if (TREE_VOLATILE (TREE_TYPE (otype))
  2867.           && ! TREE_VOLATILE (TREE_TYPE (type)))
  2868.         warning ("cast discards `volatile' from pointer target type");
  2869.       if (TREE_READONLY (TREE_TYPE (otype))
  2870.           && ! TREE_READONLY (TREE_TYPE (type)))
  2871.         warning ("cast discards `const' from pointer target type");
  2872.     }
  2873.  
  2874.       value = convert (type, value);
  2875.     }
  2876.  
  2877.   if (value == expr)
  2878.     {
  2879.       /* Always produce some operator for an explicit cast,
  2880.      so we can tell (for -pedantic) that the cast is no lvalue.  */
  2881.       tree nvalue = build (NOP_EXPR, type, value);
  2882.       TREE_LITERAL (nvalue) = TREE_LITERAL (value);
  2883.       return nvalue;
  2884.     }
  2885.   return value;
  2886. }
  2887.  
  2888. /* Build an assignment expression of lvalue LHS from value RHS.
  2889.    MODIFYCODE is the code for a binary operator that we use
  2890.    to combine the old value of LHS with RHS to get the new value.
  2891.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
  2892.  
  2893. tree
  2894. build_modify_expr (lhs, modifycode, rhs)
  2895.      tree lhs, rhs;
  2896.      enum tree_code modifycode;
  2897. {
  2898.   register tree result;
  2899.   tree newrhs;
  2900.   tree lhstype = TREE_TYPE (lhs);
  2901.   tree olhstype = lhstype;
  2902.  
  2903.   /* Types that aren't fully specified cannot be used in assignments.  */
  2904.   lhs = require_complete_type (lhs);
  2905.  
  2906.   /* Avoid duplicate error messages from operands that had errors.  */
  2907.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  2908.     return error_mark_node;
  2909.  
  2910.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2911.      Strip such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
  2912.   if (TREE_CODE (rhs) == NOP_EXPR
  2913.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)))
  2914.     rhs = TREE_OPERAND (rhs, 0);
  2915.  
  2916.   newrhs = rhs;
  2917.  
  2918.   /* Handle control structure constructs used as "lvalues".  */
  2919.  
  2920.   if (!pedantic)
  2921.     switch (TREE_CODE (lhs))
  2922.       {
  2923.     /* Handle (a, b) used as an "lvalue".  */
  2924.       case COMPOUND_EXPR:
  2925.     return build (COMPOUND_EXPR, lhstype,
  2926.               TREE_OPERAND (lhs, 0),
  2927.               build_modify_expr (TREE_OPERAND (lhs, 1),
  2928.                      modifycode, rhs));
  2929.  
  2930.     /* Handle (a ? b : c) used as an "lvalue".  */
  2931.       case COND_EXPR:
  2932.     rhs = save_expr (rhs);
  2933.     {
  2934.       /* Produce (a ? (b = rhs) : (c = rhs))
  2935.          except that the RHS goes through a save-expr
  2936.          so the code to compute it is only emitted once.  */
  2937.       tree cond
  2938.         = build_conditional_expr
  2939.           (TREE_OPERAND (lhs, 0),
  2940.            build_modify_expr (TREE_OPERAND (lhs, 1),
  2941.                   modifycode, rhs),
  2942.            build_modify_expr (TREE_OPERAND (lhs, 2),
  2943.                   modifycode, rhs));
  2944.       /* Make sure the code to compute the rhs comes out
  2945.          before the split.  */
  2946.       return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  2947.             /* Cast to void to suppress warning
  2948.                from warn_if_unused_value.  */
  2949.             convert (void_type_node, rhs),
  2950.             cond);
  2951.     }
  2952.       }
  2953.  
  2954.   /* If a binary op has been requested, combine the old LHS value with the RHS
  2955.      producing the value we should actually store into the LHS.  */
  2956.  
  2957.   if (modifycode != NOP_EXPR)
  2958.     {
  2959.       lhs = stabilize_reference (lhs);
  2960.       newrhs = build_binary_op (modifycode, lhs, rhs);
  2961.     }
  2962.  
  2963.   /* Handle a cast used as an "lvalue".
  2964.      We have already performed any binary operator using the value as cast.
  2965.      Now convert the result to the true type of the lhs and store there;
  2966.      then cast the result back to the specified type to be the value
  2967.      of the assignment.  */
  2968.  
  2969.   if (!pedantic)
  2970.     switch (TREE_CODE (lhs))
  2971.       {
  2972.       case NOP_EXPR:
  2973.       case CONVERT_EXPR:
  2974.       case FLOAT_EXPR:
  2975.       case FIX_TRUNC_EXPR:
  2976.       case FIX_FLOOR_EXPR:
  2977.       case FIX_ROUND_EXPR:
  2978.       case FIX_CEIL_EXPR:
  2979.     if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  2980.         || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
  2981.       newrhs = default_conversion (newrhs);
  2982.     {
  2983.       tree inner_lhs = TREE_OPERAND (lhs, 0);
  2984.       tree result = build_modify_expr (inner_lhs, NOP_EXPR,
  2985.                        convert (TREE_TYPE (inner_lhs),
  2986.                             newrhs));
  2987.       return convert (TREE_TYPE (lhs), result);
  2988.     }
  2989.       }
  2990.  
  2991.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  2992.      Reject anything strange now.  */
  2993.  
  2994.   if (!lvalue_or_else (lhs, "assignment"))
  2995.     return error_mark_node;
  2996.  
  2997.   /* Warn about storing in something that is `const'.  */
  2998.  
  2999.   if (TREE_READONLY (lhs)
  3000.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  3001.        || TREE_CODE (lhstype) == UNION_TYPE)
  3002.       && C_TYPE_FIELDS_READONLY (lhstype)))
  3003.     readonly_warning (lhs, "assignment");
  3004.  
  3005.   /* If storing into a structure or union member,
  3006.      it has probably been given type `int'.
  3007.      Compute the type that would go with
  3008.      the actual amount of storage the member occupies.  */
  3009.  
  3010.   if (TREE_CODE (lhs) == COMPONENT_REF
  3011.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  3012.       || TREE_CODE (lhstype) == REAL_TYPE
  3013.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  3014.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  3015.  
  3016.   /* If storing in a field that is in actuality a short or narrower than one,
  3017.      we must store in the field in its actual type.  */
  3018.  
  3019.   if (lhstype != TREE_TYPE (lhs))
  3020.     {
  3021.       lhs = copy_node (lhs);
  3022.       TREE_TYPE (lhs) = lhstype;
  3023.     }
  3024.  
  3025.   /* Convert new value to destination type.  */
  3026.  
  3027.   newrhs = convert_for_assignment (lhstype, newrhs, "assignment");
  3028.   if (TREE_CODE (newrhs) == ERROR_MARK)
  3029.     return error_mark_node;
  3030.  
  3031.   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
  3032.   TREE_VOLATILE (result) = 1;
  3033.  
  3034.   /* If we got the LHS in a different type for storing in,
  3035.      convert the result back to the nominal type of LHS
  3036.      so that the value we return always has the same type
  3037.      as the LHS argument.  */
  3038.  
  3039.   if (olhstype == TREE_TYPE (result))
  3040.     return result;
  3041.   return convert_for_assignment (olhstype, result, "assignment");
  3042. }
  3043.  
  3044. /* Return 0 if EXP is not a valid lvalue in this language
  3045.    even though `lvalue_or_else' would accept it.  */
  3046.  
  3047. int
  3048. language_lvalue_valid (exp)
  3049.      tree exp;
  3050. {
  3051.   return 1;
  3052. }
  3053.  
  3054. /* Convert value RHS to type TYPE as preparation for an assignment
  3055.    to an lvalue of type TYPE.
  3056.    The real work of conversion is done by `convert'.
  3057.    The purpose of this function is to generate error messages
  3058.    for assignments that are not allowed in C.
  3059.    ERRTYPE is a string to use in error messages:
  3060.    "assignment", "return", etc.  */
  3061.  
  3062. static tree
  3063. convert_for_assignment (type, rhs, errtype)
  3064.      tree type, rhs;
  3065.      char *errtype;
  3066. {
  3067.   register enum tree_code codel = TREE_CODE (type);
  3068.   register tree rhstype;
  3069.   register enum tree_code coder;
  3070.  
  3071.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  3072.      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
  3073.   if (TREE_CODE (rhs) == NOP_EXPR
  3074.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)))
  3075.     rhs = TREE_OPERAND (rhs, 0);
  3076.  
  3077.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  3078.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
  3079.     rhs = default_conversion (rhs);
  3080.  
  3081.   rhstype = TREE_TYPE (rhs);
  3082.   coder = TREE_CODE (rhstype);
  3083.  
  3084.   if (coder == ERROR_MARK)
  3085.     return error_mark_node;
  3086.  
  3087.   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  3088.     return rhs;
  3089.  
  3090.   if (coder == VOID_TYPE)
  3091.     {
  3092.       error ("void value not ignored as it ought to be");
  3093.       return error_mark_node;
  3094.     }
  3095.   /* Arithmetic types all interconvert, and enum is treated like int.  */
  3096.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE)
  3097.        &&
  3098.       (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE))
  3099.     {
  3100.       return convert (type, rhs);
  3101.     }
  3102.   /* Conversions among pointers */
  3103.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  3104.     {
  3105.       register tree ttl = TREE_TYPE (type);
  3106.       register tree ttr = TREE_TYPE (rhstype);
  3107.       /* Any non-function converts to a [const][volatile] void *
  3108.      and vice versa; otherwise, targets must be the same.
  3109.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  3110.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  3111.       || TYPE_MAIN_VARIANT (ttr) == void_type_node
  3112.       || comp_target_types (type, rhstype))
  3113.     {
  3114.       if (pedantic
  3115.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  3116.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  3117.           ||
  3118.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  3119.            && TREE_CODE (ttl) == FUNCTION_TYPE)))
  3120.         warning ("%s between incompatible pointer types", errtype);
  3121.       else
  3122.         {
  3123.           if (! TREE_READONLY (ttl) && TREE_READONLY (ttr))
  3124.         warning ("%s of non-const * pointer from const *", errtype);
  3125.           if (! TREE_VOLATILE (ttl) && TREE_VOLATILE (ttr))
  3126.         warning ("%s of non-volatile * pointer from volatile *", errtype);
  3127.         }
  3128.     }
  3129.       else
  3130.     warning ("%s between incompatible pointer types", errtype);
  3131.       return convert (type, rhs);
  3132.     }
  3133.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  3134.     {
  3135.       if (! integer_zerop (rhs))
  3136.     {
  3137.       warning ("%s of pointer from integer lacks a cast", errtype);
  3138.       return convert (type, rhs);
  3139.     }
  3140.       return null_pointer_node;
  3141.     }
  3142.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  3143.     {
  3144.       warning ("%s of integer from pointer lacks a cast", errtype);
  3145.       return convert (type, rhs);
  3146.     }
  3147.  
  3148.   error ("incompatible types in %s", errtype);
  3149.   return error_mark_node;
  3150. }
  3151.  
  3152. /* Return nonzero if VALUE is a valid constant-valued expression
  3153.    for use in initializing a static variable; one that can be an
  3154.    element of a "constant" initializer.
  3155.  
  3156.    Return 1 if the value is absolute; return 2 if it is relocatable.
  3157.    We assume that VALUE has been folded as much as possible;
  3158.    therefore, we do not need to check for such things as
  3159.    arithmetic-combinations of integers.  */
  3160.  
  3161. static int
  3162. initializer_constant_valid_p (value)
  3163.      tree value;
  3164. {
  3165.   switch (TREE_CODE (value))
  3166.     {
  3167.     case CONSTRUCTOR:
  3168.       return TREE_STATIC (value);
  3169.  
  3170.     case INTEGER_CST:
  3171.     case REAL_CST:
  3172.     case STRING_CST:
  3173.       return 1;
  3174.  
  3175.     case ADDR_EXPR:
  3176.       return 2;
  3177.  
  3178.     case CONVERT_EXPR:
  3179.     case NOP_EXPR:
  3180.       /* Allow conversions between types of the same kind.  */
  3181.       if (TREE_CODE (TREE_TYPE (value))
  3182.       == TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))))
  3183.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3184.       /* Allow (int) &foo.  */
  3185.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  3186.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
  3187.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3188.       return 0;
  3189.  
  3190.     case PLUS_EXPR:
  3191.       {
  3192.     int valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3193.     int valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  3194.     if (valid0 == 1 && valid1 == 2)
  3195.       return 2;
  3196.     if (valid0 == 2 && valid1 == 1)
  3197.       return 2;
  3198.     return 0;
  3199.       }
  3200.  
  3201.     case MINUS_EXPR:
  3202.       {
  3203.     int valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3204.     int valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  3205.     if (valid0 == 2 && valid1 == 1)
  3206.       return 2;
  3207.     return 0;
  3208.       }
  3209.     }
  3210.  
  3211.   return 0;
  3212. }
  3213.  
  3214. /* Perform appropriate conversions on the initial value of a variable,
  3215.    store it in the declaration DECL,
  3216.    and print any error messages that are appropriate.
  3217.    If the init is invalid, store an ERROR_MARK.  */
  3218.  
  3219. void
  3220. store_init_value (decl, init)
  3221.      tree decl, init;
  3222. {
  3223.   register tree value, type;
  3224.  
  3225.   /* If variable's type was invalidly declared, just ignore it.  */
  3226.  
  3227.   type = TREE_TYPE (decl);
  3228.   if (TREE_CODE (type) == ERROR_MARK)
  3229.     return;
  3230.  
  3231.   /* Digest the specified initializer into an expression.  */
  3232.  
  3233.   value = digest_init (type, init, 0);
  3234.  
  3235.   /* Store the expression if valid; else report error.  */
  3236.  
  3237.   if (value == error_mark_node)
  3238.     ;
  3239.   else if (TREE_STATIC (decl) && ! TREE_LITERAL (value))
  3240.     {
  3241.       error ("initializer for static variable is not constant");
  3242.       value = error_mark_node;
  3243.     }
  3244.   else if (TREE_STATIC (decl)
  3245.        && ! initializer_constant_valid_p (value))
  3246.     {
  3247.       error ("initializer for static variable uses complicated arithmetic");
  3248.       value = error_mark_node;
  3249.     }
  3250.   else
  3251.     {
  3252.       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
  3253.     {
  3254.       if (! TREE_LITERAL (value))
  3255.         warning ("aggregate initializer is not constant");
  3256.       else if (! TREE_STATIC (value))
  3257.         warning ("aggregate initializer uses complicated arithmetic");
  3258.     }
  3259.     }
  3260.   DECL_INITIAL (decl) = value;
  3261. }
  3262.  
  3263. /* Digest the parser output INIT as an initializer for type TYPE.
  3264.    Return a C expression of type TYPE to represent the initial value.
  3265.  
  3266.    If TAIL is nonzero, it points to a variable holding a list of elements
  3267.    of which INIT is the first.  We update the list stored there by
  3268.    removing from the head all the elements that we use.
  3269.    Normally this is only one; we use more than one element only if
  3270.    TYPE is an aggregate and INIT is not a constructor.  */
  3271.  
  3272. tree
  3273. digest_init (type, init, tail)
  3274.      tree type, init, *tail;
  3275. {
  3276.   enum tree_code code = TREE_CODE (type);
  3277.   tree element = 0;
  3278.   tree old_tail_contents;
  3279.   /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
  3280.      tree node which has no TREE_TYPE.  */
  3281.   int raw_constructor
  3282.     = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;
  3283.  
  3284.   /* By default, assume we use one element from a list.
  3285.      We correct this later in the sole case where it is not true.  */
  3286.  
  3287.   if (tail)
  3288.     {
  3289.       old_tail_contents = *tail;
  3290.       *tail = TREE_CHAIN (*tail);
  3291.     }
  3292.  
  3293.   if (init == error_mark_node)
  3294.     return init;
  3295.  
  3296.   if (init && raw_constructor
  3297.       && CONSTRUCTOR_ELTS (init) != 0
  3298.       && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
  3299.     element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
  3300.  
  3301.   /* Any type can be initialized from an expression of the same type,
  3302.      optionally with braces.  */
  3303.  
  3304.   if (init && (TREE_TYPE (init) == type
  3305.            || (code == ARRAY_TYPE && TREE_TYPE (init)
  3306.            && comptypes (TREE_TYPE (init), type))))
  3307.     {
  3308.       if (pedantic && code == ARRAY_TYPE
  3309.       && TREE_CODE (init) != STRING_CST)
  3310.     warning ("ANSI C forbids initializing array from array expression");
  3311.       if (optimize && TREE_READONLY (init) && TREE_CODE (init) == VAR_DECL)
  3312.     return decl_constant_value (init);
  3313.       return init;
  3314.     }
  3315.  
  3316.   if (element && (TREE_TYPE (element) == type
  3317.           || (code == ARRAY_TYPE && TREE_TYPE (element)
  3318.               && comptypes (TREE_TYPE (element), type))))
  3319.     {
  3320.       if (pedantic && code == ARRAY_TYPE)
  3321.     warning ("ANSI C forbids initializing array from array expression");
  3322.       if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
  3323.     warning ("single-expression nonscalar initializer has braces");
  3324.       if (optimize && TREE_READONLY (element) && TREE_CODE (element) == VAR_DECL)
  3325.     return decl_constant_value (element);
  3326.       return element;
  3327.     }
  3328.  
  3329.   /* Check for initializing a union by its first field.
  3330.      Such an initializer must use braces.  */
  3331.  
  3332.   if (code == UNION_TYPE)
  3333.     {
  3334.       tree result;
  3335.  
  3336.       if (TYPE_FIELDS (type) == 0)
  3337.     {
  3338.       error ("union with no members cannot be initialized");
  3339.       return error_mark_node;
  3340.     }
  3341.       if (! raw_constructor)
  3342.     {
  3343.       error ("type mismatch in initialization");
  3344.       return error_mark_node;
  3345.     }
  3346.       if (element == 0)
  3347.     {
  3348.       error ("union initializer requires one element");
  3349.       return error_mark_node;
  3350.     }
  3351.       /* Take just the first element from within the constructor
  3352.      and it should match the type of the first element.  */
  3353.       element = digest_init (TREE_TYPE (TYPE_FIELDS (type)), element, 0);
  3354.       result = build (CONSTRUCTOR, type, 0, build_tree_list (0, element));
  3355.       TREE_LITERAL (result) = TREE_LITERAL (element);
  3356.       TREE_STATIC (result) = (initializer_constant_valid_p (element)
  3357.                   && TREE_LITERAL (element));
  3358.       return result;
  3359.     }
  3360.  
  3361.   /* Initialization of an array of chars from a string constant
  3362.      optionally enclosed in braces.  */
  3363.  
  3364.   if (code == ARRAY_TYPE)
  3365.     {
  3366.       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
  3367.       if ((typ1 == char_type_node
  3368.        || typ1 == signed_char_type_node
  3369.        || typ1 == unsigned_char_type_node
  3370.        || typ1 == unsigned_type_node
  3371.        || typ1 == integer_type_node)
  3372.       && ((init && TREE_CODE (init) == STRING_CST)
  3373.           || (element && TREE_CODE (element) == STRING_CST)))
  3374.     {
  3375.       tree string = element ? element : init;
  3376.  
  3377.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
  3378.            != char_type_node)
  3379.           && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
  3380.         {
  3381.           error ("char-array initialized from wide string");
  3382.           return error_mark_node;
  3383.         }
  3384.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
  3385.            == char_type_node)
  3386.           && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
  3387.         {
  3388.           error ("int-array initialized from non-wide string");
  3389.           return error_mark_node;
  3390.         }
  3391.  
  3392.       if (pedantic && typ1 != char_type_node)
  3393.         warning ("ANSI C forbids string initializer except for `char' elements");
  3394.       TREE_TYPE (string) = type;
  3395.       if (TYPE_DOMAIN (type) != 0
  3396.           && TREE_LITERAL (TYPE_SIZE (type)))
  3397.         {
  3398.           register int size
  3399.         = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
  3400.           size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  3401.           /* Subtract 1 because it's ok to ignore the terminating null char
  3402.          that is counted in the length of the constant.  */
  3403.           if (size < TREE_STRING_LENGTH (string) - 1)
  3404.         warning ("initializer-string for array of chars is too long");
  3405.         }
  3406.       return string;
  3407.     }
  3408.     }
  3409.  
  3410.   /* Handle scalar types, including conversions.  */
  3411.  
  3412.   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
  3413.       || code == ENUMERAL_TYPE)
  3414.     {
  3415.       if (raw_constructor)
  3416.     {
  3417.       if (element == 0)
  3418.         {
  3419.           error ("initializer for scalar variable requires one element");
  3420.           return error_mark_node;
  3421.         }
  3422.       init = element;
  3423.     }
  3424.  
  3425.       if (TREE_CODE (init) == CONSTRUCTOR)
  3426.     {
  3427.       error ("initializer for scalar has extra braces");
  3428.       return error_mark_node;
  3429.     }
  3430.  
  3431.       return convert_for_assignment (type, default_conversion (init),
  3432.                      "initialization");
  3433.     }
  3434.  
  3435.   /* Come here only for records and arrays.  */
  3436.  
  3437.   if (TYPE_SIZE (type) && ! TREE_LITERAL (TYPE_SIZE (type)))
  3438.     {
  3439.       error ("variable-sized object may not be initialized");
  3440.       return error_mark_node;
  3441.     }
  3442.  
  3443.   if (code == ARRAY_TYPE || code == RECORD_TYPE)
  3444.     {
  3445.       if (raw_constructor)
  3446.     return process_init_constructor (type, init, 0);
  3447.       else if (tail != 0)
  3448.     {
  3449.       *tail = old_tail_contents;
  3450.       return process_init_constructor (type, 0, tail);
  3451.     }
  3452.       else if (flag_traditional)
  3453.     /* Traditionally one can say `char x[100] = 0;'.  */
  3454.     return process_init_constructor (type,
  3455.                      build_nt (CONSTRUCTOR, 0,
  3456.                            tree_cons (0, init, 0)),
  3457.                      0);
  3458.     }
  3459.  
  3460.   error ("invalid initializer");
  3461.   return error_mark_node;
  3462. }
  3463.  
  3464. /* Process a constructor for a variable of type TYPE.
  3465.    The constructor elements may be specified either with INIT or with ELTS,
  3466.    only one of which should be non-null.
  3467.  
  3468.    If INIT is specified, it is a CONSTRUCTOR node which is specifically
  3469.    and solely for initializing this datum.
  3470.  
  3471.    If ELTS is specified, it is the address of a variable containing
  3472.    a list of expressions.  We take as many elements as we need
  3473.    from the head of the list and update the list.
  3474.  
  3475.    In the resulting constructor, TREE_LITERAL is set if all elts are
  3476.    constant, and TREE_STATIC is set if, in addition, all elts are simple enough
  3477.    constants that the assembler and linker can compute them.  */
  3478.  
  3479. static tree
  3480. process_init_constructor (type, init, elts)
  3481.      tree type, init, *elts;
  3482. {
  3483.   register tree tail;
  3484.   /* List of the elements of the result constructor,
  3485.      in reverse order.  */
  3486.   register tree members = NULL;
  3487.   tree result;
  3488.   int allconstant = 1;
  3489.   int allsimple = 1;
  3490.   int error = 0;
  3491.  
  3492.   /* Make TAIL be the list of elements to use for the initialization,
  3493.      no matter how the data was given to us.  */
  3494.  
  3495.   if (elts)
  3496.     tail = *elts;
  3497.   else
  3498.     tail = CONSTRUCTOR_ELTS (init);
  3499.  
  3500.   /* Gobble as many elements as needed, and make a constructor or initial value
  3501.      for each element of this aggregate.  Chain them together in result.
  3502.      If there are too few, use 0 for each scalar ultimate component.  */
  3503.  
  3504.   if (TREE_CODE (type) == ARRAY_TYPE)
  3505.     {
  3506.       tree domain = TYPE_DOMAIN (type);
  3507.       register long len;
  3508.       register int i;
  3509.  
  3510.       if (domain)
  3511.     len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
  3512.       - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
  3513.         + 1;
  3514.       else
  3515.     len = -1;  /* Take as many as there are */
  3516.  
  3517.       for (i = 0; (len < 0 || i < len) && tail != 0; i++)
  3518.     {
  3519.       register tree next1;
  3520.  
  3521.       if (TREE_VALUE (tail) != 0)
  3522.         {
  3523.           tree tail1 = tail;
  3524.           next1 = digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  3525.                    TREE_VALUE (tail), &tail1);
  3526.           if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
  3527.         abort ();
  3528.           tail = tail1;
  3529.         }
  3530.       else
  3531.         {
  3532.           next1 = error_mark_node;
  3533.           tail = TREE_CHAIN (tail);
  3534.         }
  3535.  
  3536.       if (next1 == error_mark_node)
  3537.         error = 1;
  3538.       else if (!TREE_LITERAL (next1))
  3539.         allconstant = 0;
  3540.       else if (! initializer_constant_valid_p (next1))
  3541.         allsimple = 0;
  3542.       members = tree_cons (NULL_TREE, next1, members);
  3543.     }
  3544.     }
  3545.   if (TREE_CODE (type) == RECORD_TYPE)
  3546.     {
  3547.       register tree field;
  3548.  
  3549.       for (field = TYPE_FIELDS (type); field && tail;
  3550.        field = TREE_CHAIN (field))
  3551.     {
  3552.       register tree next1;
  3553.  
  3554.       if (! DECL_NAME (field))
  3555.         {
  3556.           members = tree_cons (field, integer_zero_node, members);
  3557.           continue;
  3558.         }
  3559.  
  3560.       if (TREE_VALUE (tail) != 0)
  3561.         {
  3562.           tree tail1 = tail;
  3563.           next1 = digest_init (TREE_TYPE (field),
  3564.                    TREE_VALUE (tail), &tail1);
  3565.           if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
  3566.         abort ();
  3567.           tail = tail1;
  3568.         }
  3569.       else
  3570.         {
  3571.           next1 = error_mark_node;
  3572.           tail = TREE_CHAIN (tail);
  3573.         }
  3574.  
  3575.       if (next1 == error_mark_node)
  3576.         error = 1;
  3577.       else if (!TREE_LITERAL (next1))
  3578.         allconstant = 0;
  3579.       else if (! initializer_constant_valid_p (next1))
  3580.         allsimple = 0;
  3581.       members = tree_cons (field, next1, members);
  3582.     }
  3583.     }
  3584.  
  3585.   /* If arguments were specified as a list, just remove the ones we used.  */
  3586.   if (elts)
  3587.     *elts = tail;
  3588.   /* If arguments were specified as a constructor,
  3589.      complain unless we used all the elements of the constructor.  */
  3590.   else if (tail)
  3591.     warning ("excess elements in aggregate initializer");
  3592.  
  3593.   if (error)
  3594.     return error_mark_node;
  3595.  
  3596.   result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
  3597.   if (allconstant) TREE_LITERAL (result) = 1;
  3598.   if (allconstant && allsimple) TREE_STATIC (result) = 1;
  3599.   return result;
  3600. }
  3601.  
  3602. /* Expand an ASM statement with operands, handling output operands
  3603.    that are not variables or INDIRECT_REFS by transforming such
  3604.    cases into cases that expand_asm_operands can handle.
  3605.  
  3606.    Arguments are same as for expand_asm_operands.  */
  3607.  
  3608. void
  3609. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  3610.      tree string, outputs, inputs, clobbers;
  3611.      int vol;
  3612.      char *filename;
  3613.      int line;
  3614. {
  3615.   int noutputs = list_length (outputs);
  3616.   register int i;
  3617.   /* o[I] is the place that output number I should be written.  */
  3618.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  3619.   register tree tail;
  3620.  
  3621.   /* Record the contents of OUTPUTS before it is modifed.  */
  3622.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  3623.     o[i] = TREE_VALUE (tail);
  3624.  
  3625. #if 0  /* Don't do this--it screws up operands expected to be in memory.  */
  3626.   /* Perform default conversions on all inputs.  */
  3627.   for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
  3628.     TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
  3629. #endif
  3630.  
  3631.   /* Generate the ASM_OPERANDS insn;
  3632.      store into the TREE_VALUEs of OUTPUTS some trees for
  3633.      where the values were actually stored.  */
  3634.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  3635.  
  3636.   /* Copy all the intermediate outputs into the specified outputs.  */
  3637.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  3638.     {
  3639.       if (o[i] != TREE_VALUE (tail))
  3640.     expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  3641.              0, VOIDmode, 0);
  3642.       /* Detect modification of read-only values.
  3643.      (Otherwise done by build_modify_expr.)  */
  3644.       else
  3645.     {
  3646.       tree type = TREE_TYPE (o[i]);
  3647.       if (TREE_READONLY (o[i])
  3648.           || ((TREE_CODE (type) == RECORD_TYPE
  3649.            || TREE_CODE (type) == UNION_TYPE)
  3650.           && C_TYPE_FIELDS_READONLY (type)))
  3651.         readonly_warning (o[i], "modification by `asm'");
  3652.     }
  3653.     }
  3654.  
  3655.   /* Those MODIFY_EXPRs could do autoincrements.  */
  3656.   emit_queue ();
  3657. }
  3658.  
  3659. /* Expand a C `return' statement.
  3660.    RETVAL is the expression for what to return,
  3661.    or a null pointer for `return;' with no value.  */
  3662.  
  3663. void
  3664. c_expand_return (retval)
  3665.      tree retval;
  3666. {
  3667.   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
  3668.  
  3669.   if (TREE_THIS_VOLATILE (current_function_decl))
  3670.     warning ("function declared `volatile' has a `return' statement");
  3671.  
  3672.   if (!retval)
  3673.     {
  3674.       current_function_returns_null = 1;
  3675.       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
  3676.     warning ("`return' with no value, in function returning non-void");
  3677.       expand_null_return ();
  3678.     }
  3679.   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
  3680.     {
  3681.       current_function_returns_null = 1;
  3682.       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  3683.     warning ("`return' with a value, in function returning void");
  3684.       expand_return (retval);
  3685.     }
  3686.   else
  3687.     {
  3688.       tree t = convert_for_assignment (valtype, retval, "return");
  3689.       tree res = DECL_RESULT (current_function_decl);
  3690.       t = build (MODIFY_EXPR, TREE_TYPE (res),
  3691.          res, convert (TREE_TYPE (res), t));
  3692.       expand_return (t);
  3693.       current_function_returns_value = 1;
  3694.     }
  3695. }
  3696.  
  3697. /* Start a C switch statement, testing expression EXP.
  3698.    Return EXP if it is valid, an error node otherwise.  */
  3699.  
  3700. tree
  3701. c_expand_start_case (exp)
  3702.      tree exp;
  3703. {
  3704.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  3705.   tree type = TREE_TYPE (exp);
  3706.  
  3707.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  3708.     {
  3709.       error ("switch quantity not an integer");
  3710.       exp = error_mark_node;
  3711.     }
  3712.   else
  3713.     {
  3714.       tree index;
  3715.  
  3716.       exp = default_conversion (exp);
  3717.       type = TREE_TYPE (exp);
  3718.       index = get_unwidened (exp, 0);
  3719.       /* We can't strip a conversion from a signed type to an unsigned,
  3720.      because if we did, int_fits_type_p would do the wrong thing
  3721.      when checking case values for being in range,
  3722.      and it's too hard to do the right thing.  */
  3723.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  3724.       == TREE_UNSIGNED (TREE_TYPE (index)))
  3725.     exp = index;
  3726.     }
  3727.  
  3728.   expand_start_case (1, exp, type);
  3729.  
  3730.   return exp;
  3731. }
  3732.